我的列表视图的页眉和页脚部分附加声明
ListView = (ListView)findViewById(R.id.favoritesList);
View header = View.inflate(this, R.layout.favourites_list_header, null);
View footer = View.inflate(this, R.layout.favourites_list_footer, null);
favouritesListView.addHeaderView(header, null, false);
favouritesListView.addFooterView(footer, null, false);
favouritesListView.setHeaderDividersEnabled(false);
favouritesListView.setFooterDividersEnabled(false);
favouritesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
这是我的getView方法
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.favouritestext, null);
holder=new ViewHolder();
// my code goes here...
}
}
我的Logcat
10-30 15:06:39.501: ERROR/AndroidRuntime(337): FATAL EXCEPTION: main
10-30 15:06:39.501: ERROR/AndroidRuntime(337): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at java.util.ArrayList.get(ArrayList.java:311)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.ListView.dispatchDraw(ListView.java:2991)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6846)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.AbsListView.draw(AbsListView.java:2257)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.View.draw(View.java:6743)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewRoot.draw(ViewRoot.java:1407)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.os.Looper.loop(Looper.java:123)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at java.lang.reflect.Method.invoke(Method.java:521)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-30 15:06:39.501: ERROR/AndroidRuntime(337): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我使用此addHeaderView(View,object,Slectable)添加了标题; 这是崩溃的原因,而是使用addHeaderView(View)
添加标头答案 1 :(得分:0)
适配器用于创建单个行的数据超出索引范围。
例如,如果您使用的是5个项目的数组,但在创建适配器视图时,您正尝试访问该数组的第6个项目。
希望这可以帮助您指出问题,否则发布代码。
答案 2 :(得分:0)
重现步骤
1列表
2套适配器
3添加页脚或标题
4 make list empty
5滚动和崩溃重现