Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>this is my answer to the this issue, u need to keep a check state for individual child and check on it when the the child is clicked. after some research, this is due to android's view lifecycle causing the view to refresh thus not keeping the state. </p> <pre><code>public class MyExpandableListAdapter extends BaseExpandableListAdapter { //Variables // Sample data set. children[i] contains the children (String[]) for groups[i]. private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" }; //headers private String[][] children = { { "Arnold", "Barry", "Chuck", "David" }, { "Ace", "Bandit", "Cha-Cha", "Deuce" }, { "Fluffy", "Snuggles" }, { "Goldy", "Bubbles" } }; private String[] group_vaues = {"PN", "DN", "CN", "FN"}; private String[][] children_values = { { "Ar", "Ba", "Ch", "Da" }, { "Ace", "Ban", "Cha", "Deu" }, { "Flu", "Snu" }, { "Gol", "Bub" } }; ArrayList&lt;ArrayList&lt;Integer&gt;&gt; check_states = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;(); private Context context; //Constructors public MyExpandableListAdapter() { } public MyExpandableListAdapter(Context c) { this.context = c; } //Set Methods public void setGroupsAndValues(String[] g, String[] v) { this.groups = g; this.group_vaues = v; } public void setChildrenAndValues(String[][] c, String[][] v) { this.children = c; this.children_values = v; //initialize the states to all 0; for(int i = 0; i &lt; c.length; i++) { ArrayList&lt;Integer&gt; tmp = new ArrayList&lt;Integer&gt;(); for(int j = 0; j &lt; c[i].length; j++) { tmp.add(0); } check_states.add(tmp); } } //Get Methods public Object getChild(int groupPosition, int childPosition) { return children[groupPosition][childPosition]; } public long getChildId(int groupPosition, int childPosition) { return childPosition; } public int getChildrenCount(int groupPosition) { return children[groupPosition].length; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View grid; LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); grid = inflater.inflate(R.layout.specialty_list_item, parent, false); final int grpPos = groupPosition; final int childPos = childPosition; TextView header = (TextView)grid.findViewById(R.id.title); header.setText(getChild(groupPosition, childPosition).toString()); final View tick = grid.findViewById(R.id.image); if(check_states.get(grpPos).get(childPos) == 1) tick.setVisibility(View.VISIBLE); else tick.setVisibility(View.GONE); grid.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { check_states.get(grpPos).set(childPos, 1); tick.setVisibility(View.VISIBLE); } }); return grid; } public Object getGroup(int groupPosition) { return groups[groupPosition]; } public int getGroupCount() { return groups.length; } public long getGroupId(int groupPosition) { return groupPosition; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View grid; if(convertView==null){ grid = new View(context); LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); grid = inflater.inflate(R.layout.specialty_header, parent, false); }else{ grid = (View)convertView; } TextView header = (TextView)grid.findViewById(R.id.specialty_header); header.setText(getGroup(groupPosition).toString()); return grid; } public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public boolean hasStableIds() { return true; } </code></pre> <p>}</p>
 

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