相关疑难解决方法(0)

Android:向ExpandableListView添加标题视图时的ClassCastException

我正在尝试向ExpandableListView添加标头,如下所示:

headerView = View.inflate(this, R.layout.header, null);
expandableListView.addHeaderView(headerView);
expandableListView.setAdapter(new SectionedAdapter(this));
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

 12-08 16:23:42.354:
 ERROR/AndroidRuntime(421): Caused by:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
 12-08 16:23:42.354:   ERROR/AndroidRuntime(421): at android.widget.ListView.clearRecycledState(ListView.java:504)
 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.resetList(ListView.java:490)
 12-08 16:23:42.354:ERROR/AndroidRuntime(421):at android.widget.ListView.setAdapter(ListView.java:422)
 12-08 16:23:42.354:ERROR/AndroidRuntime(421): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:475)
Run Code Online (Sandbox Code Playgroud)

这是在电话会议上发生的expandableListView.setAdapter(new SectionedAdapter(this)),但我无法弄清楚原因.有任何想法吗?

android classcastexception expandablelistview android-linearlayout

44
推荐指数
2
解决办法
2万
查看次数