androidexpandablelistviewexpandablelistadapter

clear ExpandableListView


I am using an ExpandableListView along with a ViewPager so in onPageSelected() I need to clear the list.

I know one way to do it for a ListView is setAdapter(null) but I get The method setAdapter(ListAdapter) is ambiguous for the type ExpandableListView error if I try it on ExpandableListView.


Solution

  • Have you tried inputting an empty adapter? Something like the following:

    ExpandableListAdapter adapter = new ExpandableListAdapter(); //or what ever adapter you use/created
    listView.setAdapter(adapter);
    

    This is not a null adapter and you will not get a null pointer. The adapter will contain no elements to display/show/populate.

    You can check if the adapter is empty by calling isEmpty().