【发布时间】:2016-05-15 17:51:10
【问题描述】:
在我的 ExpandableListView 中,我有一个作为组的行星列表,我希望在选中主要活动中的 CheckBox 时其中一个组消失。 不幸的是,这种情况发生了:
这是影响视图可见性的代码。如您所见,我将 1 作为 'groupPosition' 的 int,因此被隐藏的视图应该是土星而不是木星,无论 'groupPosition' 的值是什么,结果都是相同的。
final MyAdapter myAdapter = new MyAdapter(this, headings, childList);
expandableListView.setAdapter(myAdapter);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(checkBox.isChecked()){
myAdapter.getGroupView(1,false,findViewById(R.id.planet), expandableListView).setVisibility(View.GONE);
myAdapter.notifyDataSetChanged();
}
if(!checkBox.isChecked()){
myAdapter.getGroupView(1,false,findViewById(R.id.planet), expandableListView).setVisibility(View.VISIBLE);
myAdapter.notifyDataSetChanged();
}
}
});
提前谢谢你。
编辑:这对克里斯很有效,谢谢。现在,我怎样才能有效地将此过滤器应用于此处的其中一个子视图? (孩子是HashMap)例如。
public void childFilter(int position, boolean filterCheck) {
planet_child_shown.clear();
String str;
if(!filterCheck) {
for (List<String> l : planet_child.values()) {
for (int i = 0; i < l.size(); i++) {
if (i!=position) {
str = l.get(i);
l.add(str);
}
}
}
}
notifyDataSetChanged();
}
我试图根据它在 List 中的位置过滤掉一个字符串,并将其放回名为planet_child_shown 的自己的“显示”HashMap> 中。然而,这总是抛出一个 nullPointer,并指向我的 getChildrenCount() 方法,该方法是我在你的 getGroupCount() 之后建模的:
public int getChildrenCount(int groupPosition) {
return planet_child_shown == null ? 0 : planet_child_shown.get(mPlanetShown.get(groupPosition).name)
.size();
}
【问题讨论】:
标签: java android android-studio expandablelistview expandablelistadapter