FR073N
FR073N

Reputation: 2091

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 :

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 ?

Upvotes: 4

Views: 4277

Answers (1)

esentsov
esentsov

Reputation: 6522

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();

Upvotes: 12

Related Questions