Values of counter changes after scrolling ExpendableListView

后端 未结 2 1454
梦如初夏
梦如初夏 2020-12-04 01:24

I have an ExpandableListView of items and on list item I have TextView with two buttons to increment or decrements the value in TextView on clicks. The problem occurs every

2条回答
  •  渐次进展
    2020-12-04 01:38

    Try this adapter:

    public class ExpandableListAdapter extends BaseExpandableListAdapter {
    
    class ViewHolder {
        TextView childText;
        TextView counterText;
        Button addItemButton;
        Button deleteItemButton;
    }
    
    class ChildItem{
        String name;
        int quantity;
        ChildItem(String name, int quantity){
            this.name = name;
            this.quantity = quantity;
        }
    }
    
    class Pos{
        int group;
        int child;
        Pos(int group, int child){
            this.group = group;
            this.child = child;
        }
    }
    
    private Context context;
    private List listDataHeader;
    //private HashMap> listHashMap;
    private HashMap> listChildMap;
    
    public ExpandableListAdapter(Context context, List listDataHeader, HashMap> listHashMap) {
        this.context = context;
        this.listDataHeader = listDataHeader;
        listChildMap = new HashMap<>();
        for(int i=0; i listTemp = new ArrayList<>();
            for(int j=0; j

提交回复
热议问题