سؤال

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.

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

Try by type casting null with BaseExpandableListAdapter like below.

listview.setAdapter((BaseExpandableListAdapter)null);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top