ListView, BaseAdapter, getViewTypeCount () - How to make the adapter check getViewTypeCount () again?

I am using my BaseAdapter (standingsListAdapter) for ListView (standingsLV) . When I install the adapter:

 standingsLV.setAdapter(standingsListAdapter); 

getViewTypeCount() . But later, when I install new data in the adapter:

 standingsListAdapter.setData(data); 

where setData(data) after setting new data calls notifyDataSetChanged() :

 public void setData(StandingsModelWrapper data) { groupsData.clear(); if (data != null) { groupsData.addAll(data.getModel()); } notifyDataSetChanged(); } 

The getViewTypeCount () method is not called again. What for? How to make the adapter check getViewTypeCount () again?


Why do I need it?

  • I show tables in each line of the list. Tables have different lengths (number of rows).
  • I want to install new data in the adapter, so the length of the tables may change.

That's why the number of my view types should be recounted every time new data arrives in the list adapter.

+6
source share
2 answers

I do not think that's possible.

Get getViewTypeCount() implementation is part of the definition your adapter; it determines, regardless of the actual adapter data at any given moment, all the possible types of data that it can hold.

getViewTypeCount is called by the framework to correctly process the representations of list items, which can be very different between the different types of data stored in the adapter. When you modify the data in the adapter, the views are still being processed according to the existing definition / implementation of getViewTypeCount .

If you want to call getViewTypeCount again, create a new adapter and set a new one as a listview adapter.

+6
source

I would try:

 standingsListAdapter.notifyDataSetChanged(); 
+1
source

All Articles