android.widget.HeaderViewListAdapter cannot be cast to ***
来源:互联网 发布:淘宝商城双11 编辑:程序博客网 时间:2024/05/01 17:34
遇到这个问题的时候,网上搜索的答案一大推,但是结论却出奇的一致:setAdapter写在了addHeaderView之前了,然后你的listView在addHeader的时候,被强制转换成了HeaderViewListAdapter。解决方法就是改变下addheader和setadapter的调用位置。
但是:如果我想调用listView的getAdapter方法,并获取adapter的对象时候,我发现,不管我addHeader和setAdapter的调用顺序是怎样的,我最终获取的对象类型依然是妥妥的:HeaderViewListAdapter, 而不是我希望的BaseAdapter。
解决方法:headerviewListAdapter对象中有个getWrappedAdapter方法,可以获取你在setAdapter()时所传入参数的adapter类型。这样写就可以了:
BaseAdapter adapter = (BaseAdapter)(((HeaderViewListAdapter)listView.getAdapter()).getWrappedAdapter());
0 0
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter
- android.widget.HeaderViewListAdapter cannot be cast to ***
- [android] cannot be cast to android.widget.HeaderViewListAdapter
- Error: cannot be cast to android.widget.HeaderViewListAdapter
- 奇葩问题cannot be cast to android.widget.HeaderViewListAdapter
- cannot be cast to android.widget.HeaderViewListAdapter源码分析
- java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to com.android.mms
- 异常 java.lang.ClassCastException:cannot be cast to android.widget.HeaderViewListAdapter.的解决方法
- cannot be cast toandroid.widget.HeaderViewListAdapter
- android.widget.HeaderViewListAdapter canot be cast xxxx
- android.widget.Button cannot be cast to android.widget.Gallery
- widget.Button cannot be cast to android.widget.ListView
- git基本命令详解
- MySQL使用临时表的情况
- Java内存系列一之内存数据区域
- 解决Error:Execution failed for task ':voxryJstyle1:transformClassesWithDexFor360Debug'.
- Android兼容包Support v4.v7.v13区别与应用场景
- android.widget.HeaderViewListAdapter cannot be cast to ***
- webService学习(二)—— 调用自定义对象参数
- git命令详解
- zoj1893
- Docker 介绍及其应用
- BestCoder#86 E / hdu5808 Price List Strike Back
- 国家网信办拟立法止未成年人0到8点打网游
- Android Textview 超出最多字数省略号显示
- ORA-12154: TNS: 无法解析指定的连接标识符