问题描述
我添加了一个以listVivew的头,
查看卓=(查看)View.inflate(这一点,R.layout.search,NULL);
lv.addHeaderView(至卓飞高,空,假);
和一切都很好,直到我试图执行(当数据发生变化)
adapter.notifyDataSetChanged();
这总是崩溃我的应用程序给我以下错误:
> java.lang.ClassCastException:android.widget.HeaderViewListAdapter
如果我删除头看法则没有错误。有什么建议么?谢谢你。
看来,每当你在ListView使用页眉/页脚的意见,你的ListView被包裹着HeaderViewListAdapter。你可以解决这个使用下面的code:
<$p$p><$c$c>((YourAdapter)((HeaderViewListAdapter)lv.getAdapter()).getWrappedAdapter()).notifyDataSetChanged();I have added a view to the header of listVivew,
View TopSearch = (View) View.inflate(this, R.layout.search, null);
lv.addHeaderView(TopSearch, null, false);
And everything is fine until I try to execute (when data changes)
adapter.notifyDataSetChanged();
That always crash my application giving me following error:
> java.lang.ClassCastException: android.widget.HeaderViewListAdapter
If I remove header view then there is no error. Any suggestions? Thanks.
It seems that whenever you use header/footer views in a listview, your ListView gets wrapped with a HeaderViewListAdapter. You can fix this using the below code:
((YourAdapter)((HeaderViewListAdapter)lv.getAdapter()).getWrappedAdapter()).notifyDataSetChanged();
这篇关于执行notifyDataSetChanged时ClassCastException异常带的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!