Android 清除ExpandableListView
我正在使用Android 清除ExpandableListView,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我正在使用ExpandableListView和ViewPager,因此在onPageSelected()中,我需要清除列表 我知道对列表视图执行此操作的一种方法是setAdapter(null),但是我得到如果我在ExpandableListView上尝试,setAdapter(listapter)方法对于ExpandableListView类型是不明确的?如下所示: ExpandableListAdapter adapter = new ExpandableListAdapter(); //
ExpandableListView
和ViewPager
,因此在onPageSelected()
中,我需要清除列表
我知道对
列表视图执行此操作的一种方法是setAdapter(null)
,但是我得到如果我在ExpandableListView
上尝试,setAdapter(listapter)方法对于ExpandableListView类型是不明确的?如下所示:
ExpandableListAdapter adapter = new ExpandableListAdapter(); //or what ever adapter you use/created
listView.setAdapter(adapter);
这不是空适配器,您将不会得到空指针。适配器将不包含要显示/显示/填充的元素
您可以通过调用isEmpty()
来检查适配器是否为空,请使用下面的BaseExpandableListAdapter按类型强制转换null
listview.setAdapter((BaseExpandableListAdapter)null);