Collapse all group except selected group in expandable listview android

后端 未结 8 978
故里飘歌
故里飘歌 2020-12-23 09:20

I\'m developing android application using expandable list view. Actually what I need is, I\'m listing group, which contains child.

If I select an unexpandable group

8条回答
  •  臣服心动
    2020-12-23 09:41

    Try putting this in your ExpandableListAdapter, listView is a reference to the ExpandableListView itself. And lastExpandedGroupPosition is a integer member variable defined inside your ExpandableListAdapter.

     @Override
        public void onGroupExpanded(int groupPosition)
    
    {
    
    //collapse the old expanded group, if not the same
    
    //as new group to expand
    
    if(groupPosition != lastExpandedGroupPosition)
    
    {
    
      listView.collapseGroup(lastExpandedGroupPosition);
    
      }
    
            super.onGroupExpanded(groupPosition);           
            lastExpandedGroupPosition = groupPosition;
        }
    

提交回复
热议问题