Note that there are some explanatory texts on larger screens.

plurals
  1. POExpandable List View checkbox is checking multiple boxes
    primarykey
    data
    text
    <p>I have a expandable list view with child check boxes. The check box is defined in the child_helper xml with the id "check1". For some reason it seems that multiple check boxes are linked together instead of each being independent. For example if under the first group I select the first item, it chooses every 3rd item in that group and all the rest of the groups it selects the second item, skips two and selects the next item. </p> <p>If I select the first three items in group 1 then it selects all items in all groups. Somehow I have created 3 groups of check boxes instead of an individual check box for each child. I have been looking at a lot of tutorials that suggest the problem is fixed with a custom adapter. I am using a custom adapter, however, I am not sure how to use all of its functions. </p> <p>Perhaps the better, and much shorter question is how am I supposed to differentiate each child check box?</p> <p>Thanks </p> <p>This is the code for my listener:</p> <pre><code>expListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Log.d( "Enter_Foods", "onChildClick: "+childPosition ); CheckBox cb = (CheckBox)v.findViewById( R.id.check1 ); if( cb != null ) cb.toggle(); return false; } }); } </code></pre> <p>I think that the problem lies in one of the overridden methods in my adapter.</p> <pre><code>ExpandableListAdapter foodCategoryExpand = new ExpandableListAdapter() { @Override Allitemsenabled() other override methods... public Object getChild(int groupPosition, int childPosition) { switch (groupPosition) { case 0: return group1.get(childPosition); case 1: return group2.get(childPosition); case 2: return group3.get(childPosition); default: return null; } } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { ChildHolder holder; if (convertView == null) { holder = new ChildHolder(); LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this); convertView = inflator.inflate(R.layout.enter_foods_child_helper,null); holder.tvChild = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_child); convertView.setTag(holder); } else { holder = (ChildHolder) convertView.getTag(); } //switch based on which group (main heading) child is in switch (groupPosition) { case 0: holder.tvChild.setText(group1.get(childPosition)); break; case 1: holder.tvChild.setText(group2.get(childPosition)); break; case 2: holder.tvChild.setText(group3.get(childPosition)); break; } return convertView; } //create Group (main heading) view public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { GroupHolder holder; if (convertView == null) { holder = new GroupHolder(); LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this); //inflate xml file and then get view from that file convertView = inflator.inflate(R.layout.enter_foods_group_helper,null); holder.tvGroup = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_group); convertView.setTag(holder); } else { holder = (GroupHolder) convertView.getTag(); } //this actually gets the text we set in onCreate and sets it to the textView (holder) holder.tvGroup.setText(groupTitle.get(groupPosition)); return convertView; } other override methods </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload