Android默认组指示符ExpandableListView
我使用的是一个可扩展的列表视图,用户可以在其中选择数据 用户可以选择组或子组。为了便于区分这两个选项,我有一个无线组,有两个选项:Android默认组指示符ExpandableListView,android,expandablelistview,Android,Expandablelistview,我使用的是一个可扩展的列表视图,用户可以在其中选择数据 用户可以选择组或子组。为了便于区分这两个选项,我有一个无线组,有两个选项: 选择子项:正常可展开列表(可展开 分组并选择子对象) 选择组:所有组都已折叠,用户无法展开组 我需要的是隐藏第二个案例中的组指示器,然后在选择第一个选项时恢复它 这是我的密码: rgLink.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Overri
- 选择子项:正常可展开列表(可展开 分组并选择子对象)
- 选择组:所有组都已折叠,用户无法展开组
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;
}
}
});
对于组项,我还使用:
style="?android:attr/listSeparatorTextViewStyle"
所以基本上,我只需要一行代码来恢复默认的组指示符。如何执行此操作?您可以从当前主题获取属性:
//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();
这正是我想要的。我可以在需要时恢复组指标。请您解释一下,您是如何知道组指标样式是0指标的?是否有网站或文件?
ActainStyledAttributes
返回一个TypedArray
类型,其中包含由主题定义的值,这些值在attrs
中列出。在这两种情况下,我们都传递长度为1的attrs
array,因此结果包含1个元素,该元素的索引为0(它是数组中的索引,而不是资源id)。