Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanded listview required to expand the row one at a time

im using expanded listview in my project, i need to expand the listview only one at a time, ie i expand a item and when try to expand another item in the list the previous item which i expanded has to collapse and the new item clicked has to expand, Answers will be greatly appreciated, i'm trying with the below snippet for the on click listener..

 convertViewpar.setOnClickListener(new OnClickListener() {

    int i=1;
    public void onClick(View v) {
    i = i++;
    int[] expds = new int[100];
    expds[0]=0;
    expds[i] = groupPosition;
    if(expds[i]==expds[i-1]){
    if(isExpanded)
    expandlist.collapseGroup(i);
    else
    expandlist.expandGroup(i);
    }else{
    expandlist.collapseGroup(i-1);
     if(isExpanded)
        expandlist.collapseGroup(i);
    else
    expandlist.expandGroup(i);

    }


}
}); 
like image 514
Rakshi Avatar asked Nov 27 '22 14:11

Rakshi


1 Answers

Add implements OnGroupExpandListener at class level and in onCreate Method

    listView.setOnGroupExpandListener(this);

and add this method

/*
 * (non-Javadoc)
 * 
 * @see
 * android.widget.ExpandableListView.OnGroupExpandListener#onGroupExpand
 * (int)
 */
public void onGroupExpand(int groupPosition) {
    int len = expListAdapter.getGroupCount();

    for (int i = 0; i < len; i++) {
        if (i != groupPosition) {
            listView.collapseGroup(i);
        }
    }
}

It will works definitely.

like image 64
Anil Jadhav Avatar answered Dec 15 '22 13:12

Anil Jadhav