Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android default group indicator ExpandableListView

I'm using an expandable list view where an user can select data.

The user can select either the group, either the child. To facilitate the distinction between the 2, I have a radio group with 2 options :

  • Select the child : normal expandable list (possibility to expand group and select child)
  • Select the group : all the groups are collapsed, and the user can't expand the group

What I need, is to hide the group indicator on the second case, and then restore it when the first option is selected.

Here is my code :

rgLink.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if(checkedId == R.id.rb_link_subject){ //Here is the child mode
                mLinkType = LINK_SUBJECT;
                //elvSubject.setGroupIndicator(/*Here I need the default group indicator*/);
            }
            else{                                  //Here is the group mode
                collapseAllChildren();
                //The line below hide the group indicator
                elvSubject.setGroupIndicator(null);
                mLinkType = LINK_CATEGORY;
            }
        }
    });

I'm also using, for the group item :

style="?android:attr/listSeparatorTextViewStyle" 

So basically, I just need a one line code to restore the default group indicator. How can I do this ?

like image 407
FR073N Avatar asked Dec 16 '22 07:12

FR073N


1 Answers

You can obtain an attribute from the current theme:

 //obtain expandableListViewStyle  from theme
 TypedArray expandableListViewStyle = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.expandableListViewStyle});
 //obtain attr from style
 TypedArray groupIndicator = context.getTheme().obtainStyledAttributes(expandableListViewStyle.getResourceId(0,0),new int[]{android.R.attr.groupIndicator});
 elvSubject.setGroupIndicator(groupIndicator.getDrawable(0));
 expandableListViewStyle.recycle();
 groupIndicator.recycle();
like image 90
esentsov Avatar answered Jan 05 '23 05:01

esentsov