Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The linked answer I believe is saying you should keep track of the state of your checked groups in an array list. Then, in your <code>getChildView</code> method for your <code>BaseExpandableListAdapter</code> you would do a check to see if the group for the child is present. </p> <p>Here is my implementation, I'm using a hashmap instead of an arraylist:</p> <pre><code>public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { CheckBox check__bookmark = (CheckBox) child_row.findViewById(R.id._checkBox); if (mapp.group_bookmark_s_checked.containsKey((groupPosition)) == true) check__bookmark.setChecked(true); else check__bookmark.setChecked(false); } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { CheckBox PlayGroupSelected = (CheckBox) group_row.findViewById(R.id.bookmark_group_checkBox); if (mapp.group_bookmark_s_checked.containsKey((groupPosition)) == true) PlayGroupSelected.setChecked(true); else PlayGroupSelected.setChecked(false); PlayGroupSelected.setOnCheckedChangeListener( new BookmarkGroupCheckedChangeListener(groupPosition, mapp, group_row)); } </code></pre> <p>Now in your listener you manage the state by removing and adding to your state object. I used <code>notifyDataSetChanged()</code> because the children weren't refreshing once drawn on the check state change. Not sure if that was the right way to solve that problem but it did the trick.</p> <pre><code>class BookmarkGroupCheckedChangeListener implements OnCheckedChangeListener { private int mPosition; MyApplication mapp; RelativeLayout mgroup_row; BookmarkGroupCheckedChangeListener(int position, MyApplication app, RelativeLayout group_row) { mapp = app; mPosition = position; mgroup_row = group_row; } public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked == true) { mapp.group_bookmark_s_checked.put((mPosition), new Boolean(true)); Log.v("DEBUG:", "Group Bookmark Checked On at " + mPosition); notifyDataSetChanged(); } else if (mapp.group_bookmark_s_checked.containsKey(mPosition)) { mapp.group_bookmark_s_checked.remove((mPosition)); Log.v("DEBUG:", "Checked Off at " + mPosition); notifyDataSetChanged(); } } } </code></pre>
 

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