Change expandable indicator in ExpandableListView

前端 未结 7 804
野趣味
野趣味 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:36

    Just Create a view/Imageview where ever u want in the xml of group item example:

    
    
    
    
    
    

    And then for your ExpandableListView use a GroupClickListener to change the image for ImageView programmatically, example :

    listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                parent.smoothScrollToPosition(groupPosition);
    
                if (parent.isGroupExpanded(groupPosition)) {
                    ImageView imageView = v.findViewById(R.id.expandable_icon);
                    imageView.setImageDrawable(getResources().getDrawable(R.drawable.group_icon_not_expanded));
                } else {
                    ImageView imageView = v.findViewById(R.id.expandable_icon);
                    imageView.setImageDrawable(getResources().getDrawable(R.drawable.group_icon_expanded));
                }
                return false    ;
            }
        });
    

提交回复
热议问题