맞춤 확장 가능 목록보기를 만들었습니다. 목록보기에는 어린이 항목의 더하기 및 빼기 이미지보기와 텍스트보기가 포함되어 있습니다. 한 행에서 더하기를 클릭하면 값이 증가합니다. 1. 그러나 다음 행으로 이동하면 값 증분이 2에서 시작됩니다. 각 하위 항목의 값을 0에서 늘리고 싶습니다.확장 가능한 목록보기의 텍스트 값 늘리기
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<Group> groups;
ArrayList<Child> ch_list=new ArrayList<Child>();
private ViewHolder viewHolder; // make it global
private int count=0;
int[] myIntegerArray = new int[10100];
public class ViewHolder {
TextView tv ;
ImageView food_image;
ImageView minus,plus ;
TextView item_count;
}
public ExpandListAdapter(Context context, ArrayList<Group> groups) {
this.context = context;
this.groups = groups;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final Child child = (Child) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflator = LayoutInflater.from(parent.getContext());
convertView = inflator.inflate(R.layout.detail_list, null);
viewHolder = new ViewHolder();
viewHolder.tv = (TextView) convertView.findViewById(R.id.type);
viewHolder.food_image = (ImageView) convertView.findViewById(R.id.food_image);
viewHolder.minus = (ImageView) convertView.findViewById(R.id.minus);
viewHolder.plus = (ImageView) convertView.findViewById(R.id.plus);
viewHolder.item_count = (TextView) convertView.findViewById(R.id.count);
convertView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tv.setText(child.getChildName());
viewHolder.item_count.setText(child.getCount());
viewHolder.plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Child modelChild = groups.get(groupPosition).getItems().get(childPosition);
count = count + 1;
modelChild.setCount(count);
modelChild.setChildName(modelChild.getChildName());
// set your other items if any like above
groups.get(groupPosition).getItems().set(childPosition, child);
notifyDataSetChanged();
}
});
viewHolder.minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(count!=0) {
Child modelChild = groups.get(groupPosition).getItems().get(childPosition);
count = count - 1;
modelChild.setCount(count);
modelChild.setChildName(modelChild.getChildName());
// set your other items if any like above
groups.get(groupPosition).getItems().set(childPosition, child);
notifyDataSetChanged();
}
}
});
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Group group = (Group) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.group_item, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.group_name);
tv.setText(group.getName());
ExpandableListView eLV = (ExpandableListView) parent;
int count = getGroupCount();
if(count<1){
eLV.expandGroup(groupPosition);
// eLV.setGroupIndicator(null);
}
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
아이 모델 :
public class Child {
private String Name;
private int Image,count;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public int getImage() {
return Image;
}
public void setImage(int Image) {
this.Image = Image;
}
public void setcount(int count) {
this.count = count;
}
public int getcount() {
return count;
}
}
그룹 모델 :
public class Group {
private String name;
private ArrayList<Child> Items;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Child> getItems() {
return Items;
}
public void setItems(ArrayList<Child> Items) {
this.Items = Items;
}
}
로그 캣 오류 :
FATAL EXCEPTION: main
Process: abservetech.com.foodapp, PID: 14471
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x0
at android.content.res.Resources.getResourcePackageName(Resources.java:1871)
at android.content.res.SPRDResources.getThemeResources(SPRDResources.java:94)
at android.content.res.SPRDResources.getText(SPRDResources.java:155)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:3927)
at abservetech.com.foodapp.ExpandListAdapter.getChildView(ExpandListAdapter.java:83)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
at android.widget.AbsListView.obtainView(AbsListView.java:2280)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1271)
at android.widget.ListView.onMeasure(ListView.java:1183)
at android.view.View.measure(View.java:16512)
문제점이 제대로 증가하지 않습니다. – Nisarg
처음에는 모든 자식 항목에 대해 카운트 값이 0입니다. 첫 번째 행에서 더하기를 클릭하면 카운트 값이 0에서 1로 증가했습니다. 그 다음 두 번째 행을 클릭하면 카운트 값이 1에서 2로 증가했습니다. 두 번째 행에서 1에서 2가 아닌 0에서 1로 카운트 값을 늘리십시오. –
POJO 클래스 값을 사용하면 정적 카운트가 아닌 지금 사용합니다 – Nisarg