Android的默认组指标ExpandableListView [英] Android default group indicator ExpandableListView

查看:252
本文介绍了Android的默认组指标ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的可扩展列表视图,一个用户可以选择的数据。

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

用户可以选择任一组中,无论是儿童。为了便于2之间的区别,我有2个选项单选按钮组:

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.

下面是我的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" 

所以基本上,我只需要一个行code,恢复默认组指标。我怎样才能做到这一点?

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

推荐答案

您可以从当前主题获得一个属性:

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

这篇关于Android的默认组指标ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆