简体   繁体   中英

Expandable ListView/Checkbox Woes

I have been racking my brain and scouring many posts, but can't seem to find the answer to the dreaded state of the Expandable ListView/Checkbox problems. I can't get this to save the state. With ListView, I created a ListArray which would add and remove the position accordingly. I thought that the way around this would be to create a HashMap to do exactly the same, but it doesn't work.

Does anyone have an example of this working and the state of the checkboxes being saved?

Here is it working in ListView, but I need something similar with a HashMap -

private ListArray<Integer> checkedState = new ListArray<Integer>();

holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    checkedState.add(childPosition);
                    holder.checkbox.setSelected(true);
                    //Toast.makeText(_context,holder.txtListChild.getText() + " Selected",Toast.LENGTH_SHORT).show();
                }
                else{
                    holder.checkbox.setSelected(false);
                    checkedState.remove(childPosition).
                    //Toast.makeText(_context,holder.txtListChild.getText() + " UnSelected",Toast.LENGTH_SHORT).show();
                }
            }
        });

if(checkedState.contains((Integer)childposition) {
    holder.checkbox.setChecked(true);
} else {
    holder.checkbox.setChecked(false);
}

I ended up not using setOnCheckedChangeListener and using onClick which works great.

The answer can be found here - Expandable listview with selectall checkbox : group itemclick and scrolling bug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM