0

Hi i am working on Expandable list , but i am facing a problem that is , when ever i check a checkbox and expand that list or scroll up/down then the check box state change automatically , for example if i check first one after scroll the list ,the last one or second last got checked and the current will unchecked . i do research a lot but doesn't found anything helpful , i know is a very common issue faced by most of developers , so if you had then please suggest me . Thanks

Here is my adapter class:

public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
    List<ChildDataBean> mListDataChild;
    private Context context;
    private List<String> expandableListTitle;
    private HashMap<String, List<String>> expandableListDetail;
    public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
                                       HashMap<String, List<String>> expandableListDetail) {
        this.context = context;
        this.expandableListTitle = expandableListTitle;
        this.expandableListDetail = expandableListDetail;

    }

    @Override
    public Object getChild(int listPosition, int expandedListPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
                .get(expandedListPosition);
    }

    @Override
    public long getChildId(int listPosition, int expandedListPosition) {
        return expandedListPosition;
    }

    @Override
    public View getChildView(int listPosition, final int expandedListPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        final String expandedListText = (String) getChild(listPosition, expandedListPosition);
        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_child, null);
        }
        TextView ChildText = (TextView) convertView.findViewById(R.id.child_text);
        ChildText.setText(expandedListText);
        CheckBox ChildChecked = (CheckBox)convertView.findViewById(R.id.child_check_box);
        if (ChildChecked.isChecked())
        {
            ChildChecked.setChecked(true);
        }
        return convertView;
    }

    @Override
    public int getChildrenCount(int listPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
                .size();
    }

    @Override
    public Object getGroup(int listPosition) {
        return this.expandableListTitle.get(listPosition);
    }

    @Override
    public int getGroupCount() {
        return this.expandableListTitle.size();
    }

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

    @Override
    public View getGroupView(int listPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String listTitle = (String) getGroup(listPosition);
        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) this.context.
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_parent, null);
        }
        TextView ParentText = (TextView) convertView.findViewById(R.id.parent_text);
        ParentText.setTypeface(null, Typeface.BOLD);
        ParentText.setText(listTitle);
        return convertView;
    }

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

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) {
        return true;
    }

}
Anoop Mishra
  • 1,005
  • 2
  • 10
  • 33
  • http://stackoverflow.com/questions/32427889/checkbox-in-recyclerview-keeps-on-checking-different-items check it. it same with your problem – Linh Feb 16 '17 at 06:11

2 Answers2

0

please pass null in getChildView method like:

  checkbox.setonclicklisner(null);
user7176550
  • 1,501
  • 14
  • 19
-1

Try, if (ChildChecked.isChecked()){ChildChecked.setChecked(true);}else{ ChildChecked.setChecked(false);} this may solve your issue.