Adding Footer To Listview Throws "cannot Be Cast To Android.widget.headerviewlistadapter"
Solution 1:
There is probably not enough code to answer this question, but are you aware that if you add a header or footer to a list, the adapter automatically gets wrapped in a HeaderViewListAdapter?
See the answer in this question:
((YourAdapter)((HeaderViewListAdapter)listView.getAdapter()).getWrappedAdapter()).notifyDataSetChanged();
If you are trying to access the adapter of the list after adding a header or footer, this exception will get thrown.
Solution 2:
I found a slight cheating way around this issue. The question is still an issue and it's still unanswered.
What can be done is to add any header or footer desired during list construction (before adding adapter) and then running remove header/footer view after running the adapter.
This does add some extra work, specially if the headers or footers require any inflating
or layout management
, but it does fix the issue.
Example Code below:
addHeaders();
addFooters();
public void setAdapter(ListAdapter adapter)
{
super.setAdapter(adapter);
// Fix for issues with ListView, Fragment and header/footerhideAllHeaders();
hideAllFooters();
}
Solution 3:
Before setting adapter to listview, add dummy view as header or footer view. Then set adapter to listview. This makes listview to instance of headerviewslist. Then you can add and remove footers easily from listview as normal.
Post a Comment for "Adding Footer To Listview Throws "cannot Be Cast To Android.widget.headerviewlistadapter""