In my ListView (expandable), If a child from 'parent A' is selected, then a random child in some random parent is also simultaneously selected. There seems to be a pattern sometimes.

I can't seem to figure out what's with the strange behavior. Below, GymFaciAll is the child items and GymFaci is the title of the parent.

public class GymFaciAdapter extends BaseExpandableListAdapter {

    Context context;
    List<String> selItems;
    HashMap<String, List<String>> GymFaciAll;
    List<String> GymFaci;
    boolean state =false;


    public GymFaciAdapter(Context context,
                          List<String> GymFaci, HashMap<String, List<String>> GymFaciAll){
        this.context = context;
        this.GymFaciAll = GymFaciAll;
        this.GymFaci = GymFaci;

        selItems = new ArrayList<>();
    }
    @Override
    public int getGroupCount() {
        return GymFaci.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return GymFaciAll.get(GymFaci.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return GymFaci.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return GymFaciAll.get(GymFaci.get(groupPosition)).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        String group_title = (String) getGroup(groupPosition);
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.exp_parent, parent, false);
        }
        TextView parentTv = convertView.findViewById(R.id.parent_txt);
        parentTv.setTypeface(null, Typeface.BOLD);
        parentTv.setText(group_title);
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                             View convertView, ViewGroup parent) {

        final int mGroupPosition = groupPosition;
        final int mChildPosition = childPosition;

        final String child_title = (String) getChild(groupPosition, childPosition);
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.exp_child, parent, false);
        }
        CheckBox childCb = convertView.findViewById(R.id.checkbox_child);
        childCb.setText(child_title);
        childCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    selItems.add(child_title);
                    state = true;
                }
                else
                    if(state){
                        selItems.remove(child_title);
                    }
            }
        });
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public List<String> getSelItems() {
        return selItems;
    }
}

Child items should be checked and unchecked independent of other children from other parents.

0 Answers