Change expandable indicator in ExpandableListView

前端 未结 7 815
野趣味
野趣味 2020-11-29 18:51

Trying to create an ExpandableListView. The initial view with the groups shows up fine. However, when I click the list item, my arrow does not change. See the images below.<

7条回答
  •  余生分开走
    2020-11-29 19:31

    I am a bit late to the party but my requirement was something similar to this but something was different.

    I had 3 requirements:

    1. if a group have child then show down_arrow (V)
    2. if a group doesn't have a child then no arrow/image
    3. if a group with child expanded then show up_arrow (^)

    To achieve something similar to this:

    1. Your ExpandableListView will look something similar to this with android:groupIndicator null

       
      
    2. Your group/header layout will look something like this with text and image at the end:

    
    
    
    
    
    
    1. In your BaseExpandableListAdapter's getGroupView() method, use

           if (Objects.requireNonNull(expandableListDetail.get(expandableListTitle.get(listPosition))).size() > 0) {
           if (isExpanded) {
               ivIcon.setImageResource(R.drawable.arrow_up);
           } else {
               ivIcon.setImageResource(R.drawable.arrow_down);
           }
       }
      

    Where, expandableListTitle is group and expandableListDetail is its children

提交回复
热议问题