0

我的声明附有我的列表视图的页眉和页脚部分

 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... 

}

}

我的日志猫

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)
4

3 回答 3

1

我已经使用这个 addHeaderView(View,object,Slectable); 添加了标题 这是崩溃的原因,而是使用 addHeaderView(View) 添加标题

于 2014-08-19T07:34:51.173 回答
0

适配器用于创建单个行的数据超出索引。

例如,如果您正在使用一个包含 5 个项目的数组,但在创建适配器视图时,您正试图访问该数组的第 6 个项目。

希望这将帮助您找出问题,否则发布代码。

于 2012-10-30T09:44:38.900 回答
0

重现步骤

1 列个清单

2套适配器

3 添加页脚或页眉

4 使列表为空

5 滚动和崩溃重现

于 2017-09-04T09:53:53.217 回答