Extensible ListView

I use expandableListView for user interface design, so I am wondering how to expand the Android list, is there a way to allow only one list item, i.e. when you click and expand an element, all other elements are automatically collapsed.

thank

+7
android expandablelistview
Jul 27 '11 at 18:01
source share
3 answers

When you click on one item, you can iterate over the rest and collapse each, except for the one you just clicked ...

list.setOnGroupExpandListener(new OnGroupExpandListener() { public void onGroupExpand(int groupPosition) { int len = mAdapter.getGroupCount(); for(int i=0; i<len; i++) { if(i != groupPosition) { list.collapseGroup(i); } } } }); 
+10
Jul 27 '11 at 18:23
source share

You could do as Kieran suggested, or if you only have one open at a time, you can just keep track of which last clicked. You could do this by declaring int lastclicked in the class body, and then in the listener, as the Korean suggested, put list.collapseGroup(lastclicked)

I would give an example code, but I am on my mobile phone. Unfortunately.

But I just personally prefer to use the latter method than using a for loop. It seems more efficient.

+1
Oct 12 '11 at 0:18
source share

First of all, implement OnGroupExpandListener in your activity, which will allow you to add your default method, and after adding this default method, you need to do like this:

 @Override public void onGroupExpand(int groupPosition) { // TODO Auto-generated method stub int len = expadapter.getGroupCount(); for(int i=0;i<len;i++) { if(i!=groupPosition) { expandlst.collapseGroup(i); } } } 
0
Jul 13 2018-12-12T00:
source share



All Articles