Note that there are some explanatory texts on larger screens.

plurals
  1. PON-level ExpandableListView
    text
    copied!<p>I'm trying to implement a N-level ExpandableListView and I'm using these codes for <code>getChildView</code> and <code>getGroupView</code> :</p> <pre><code> @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) { ExpandNode child = (ExpandNode) getChild(groupPosition, childPosition); ExpandNode group = (ExpandNode) getGroup(groupPosition); if (group.hasChild()) { if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.index_expandable_list, null); } ExpandableListView expandableListView = (ExpandableListView) view.findViewById(R.id.myExpandableListView); ExpandAdapter adapter = new ExpandAdapter(context, group.getChilds()); expandableListView.setAdapter(adapter); } else { if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.index_child_row, null); } TextView childTextView = (TextView) view.findViewById(R.id.childTextView); childTextView.setText(child.getTitle().toString()); } return view; } </code></pre> <p>and :</p> <pre><code>@Override public View getGroupView(int groupPosition, boolean isLastChild, View view,ViewGroup parent) { ExpandNode group = (ExpandNode) getGroup(groupPosition); if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.index_parent_row, null); } TextView childTextView = (TextView) view.findViewById(R.id.parentTextView); childTextView.setText(group.getTitle().toString()); return view; } </code></pre> <p>The problem is when I'm using nested adapters like what you see in <code>getChildView</code> , the <code>groupPosition</code> value is always 0 in <code>getGroupView</code> in the inner adapter and always referring to the first value in the arrayList. for example: the values in the arrayList are:</p> <pre><code>Level1 level1_1 level1_2 level1_3 level2 </code></pre> <p>but it shows:</p> <pre><code>Level1 level1_1 level1_1 level1_1 level2 </code></pre> <p>It happens only when I'm using nested adapters and it works when using <code>getChildView</code> like this:</p> <pre><code> @Override public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View view, ViewGroup parent) { ExpandNode child = (ExpandNode) getChild(groupPosition, childPosition); if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.index_child_row, null); } TextView childTextView = (TextView) view.findViewById(R.id.childTextView); childTextView.setText(child.getTitle().toString()); return view; } </code></pre> <p>But it's not a N-level list anymore... Is there ay suggestion how can I fix this?</p> <p>Other implemented methods in my Adapter mentioned below :</p> <pre><code> @Override public Object getChild(int groupPosition, int childPosition) { return groups.get(groupPosition).getChilds().get(childPosition); } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public int getChildrenCount(int groupPosition) { return groups.get(groupPosition).getChilds().size(); } @Override public Object getGroup(int groupPosition) { return groups.get(groupPosition); } @Override public int getGroupCount() { return groups.size(); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int arg0, int arg1) { return true; } </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