clear ExpandableListView
Asked Answered
C

2

6

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.

Console answered 14/1, 2014 at 13:7 Comment(0)
N
7

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().

Natelson answered 14/1, 2014 at 13:19 Comment(0)
L
11

Try by type casting null with BaseExpandableListAdapter like below.

listview.setAdapter((BaseExpandableListAdapter)null);
Lachrymatory answered 18/5, 2015 at 10:57 Comment(0)
N
7

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().

Natelson answered 14/1, 2014 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.