ListView在removeFooterView时抛出异常

异常:cannot be cast to android.widget.HeaderViewListAdapter

原因:在4.4以前(API19)的系统中,要求必须在setAdapter(adapter)之前调用addFooterView(footer),否则就会引发该异常。在4.4以后就没有这样的要求了。

addFooterView() 在API level 15说明:

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.

现在:

Note: When first introduced, this method could only be called before setting the adapter with {@link #setAdapter(ListAdapter)}. Starting with {@link android.os.Build.VERSION_CODES#KITKAT}, this method may be called at any time. If the ListView's adapter does not extend {@link HeaderViewListAdapter}, it will be wrapped with a supporting instance of {@link WrapperListAdapter}.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容