【发布时间】:2015-03-07 21:03:05
【问题描述】:
我正在尝试将 HeaderView 添加到我的 EndlessListView
这里是代码
mainLayout is the parent of SwipeLayout in which ListView is placed
ViewGroup headerView = (ViewGroup) getLayoutInflater().inflate(R.layout.profile_header, (RelativeLayout) findViewById(R.id.mainLayout), false);
listView.addHeaderView(headerView, null, false);
adapter = new TrafficTweatsAdapter(this, tweatsList);
listView.setAdapter(adapter);
我收到了这个错误
Caused by: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.ListView.clearRecycledState(ListView.java:513)
at android.widget.ListView.resetList(ListView.java:499)
at android.widget.ListView.setAdapter(ListView.java:442)
at com.app.custom.EndlessListView.setAdapter(EndlessListView.java:45)
如果我输入 null 而不是 bgLayout 或返回 true,它会给我错误
java.lang.NullPointerException
at android.widget.AbsListView.obtainView(AbsListView.java:2269)
at android.widget.ListView.makeAndAddView(ListView.java:1769)
【问题讨论】:
-
能分享一下TrafficTweatsAdapter getView方法代码