我的expandableListview
中有3种孩子。
为简单起见,我想让用户选择哪一个可见,哪一个不可见。
public void setMenuItem(MenuItem item){
if(item.isChecked())
item.setChecked(false);
else item.setChecked(true);
switch(item.getItemId()){
case R.id.type0:
if(item.isChecked())adapter.type0=View.VISIBLE;
else adapter.type0=View.GONE; break;
case R.id.type1:
if(item.isChecked())adapter.type1=View.VISIBLE;
else adapter.type1=View.GONE; break;
case R.id.type2:
if(item.isChecked())adapter.type2=View.VISIBLE;
else adapter.type2=View.GONE;
break;
}
adapter.notifyDataSetChanged();
}
可扩展List自定义适配器中的getView
如下所示:
@Override
public View getChildView(int groupPosition, final int childPosition, boolean
isLastChild, View view, ViewGroup parent) {
ArrayList<Exercises> child = (ArrayList<Exercises>)childtems
.get(groupPosition);
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater)context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.expandchild, null);
}
TextView tv = (TextView) view.findViewById(R.id.expandChildText);
tv.setText(child.get(childPosition).toString());
switch(child.get(childPosition).type){
case 0 : view.setVisibility(type0);break;
case 1 : view.setVisibility(type1);break;
case 2 : view.setVisibility(type2);break;
}
return view;
}
会发生什么,可扩展的列表视图仍显示所有子项,可见性是否设置为.gone!
如果它消失了,它只显示一个空孩子,没有任何textview等,但我想完全隐藏孩子!
那里的诀窍是什么? 一个解决方案当然是从适配器中删除特定数据,但我认为这就像拿一把大锤来破解坚果......