Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 清除ExpandableListView_Android_Expandablelistview_Expandablelistadapter - Fatal编程技术网

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