清除ExpandableListView

hyp*_*d09 6 android expandablelistview expandablelistadapter

我正在使用一个ExpandableListView,ViewPager所以onPageSelected()我需要清除列表.

我知道有一种方法可以做到这ListView一点setAdapter(null)但是The method setAdapter(ListAdapter) is ambiguous for the type ExpandableListView如果我尝试的话我会收到错误ExpandableListView.

Pra*_*sad 10

尝试使用BaseExpandableListAdapter类型转换null,如下所示.

listview.setAdapter((BaseExpandableListAdapter)null);
Run Code Online (Sandbox Code Playgroud)


wse*_*eme 7

你试过输入一个空的适配器吗?类似于以下内容:

ExpandableListAdapter adapter = new ExpandableListAdapter(); //or what ever adapter you use/created
listView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

这不是null适配器,您将不会获得空指针,并且适配器将不包含要显示/显示/填充的元素.

你可以adapter通过调用来检查它是否为空isEmpty()