HeaderViewListAdapter随机崩溃 [英] HeaderViewListAdapter randomly crashes

查看:1894
本文介绍了HeaderViewListAdapter随机崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到在crashlytics随机崩溃,我无法模拟。它随机崩溃都在Android V2和V4,但非常非常罕见

I am getting random crash in crashlytics and I can not simulate it. It crashes randomly both on Android V2 and V4 but very very rarely:

java.lang.IndexOutOfBoundsException: Invalid index 3, size is 0
   at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
   at java.util.ArrayList.get(ArrayList.java:311)
   at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:225)
   at android.widget.AbsListView.obtainView(AbsListView.java:1498)
   at android.widget.ListView.makeAndAddView(ListView.java:1749)
   at android.widget.ListView.fillSpecific(ListView.java:1294)
   at android.widget.ListView.layoutChildren(ListView.java:1580)
   at android.widget.AbsListView.onLayout(AbsListView.java:1349)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:801)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1263)
   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1137)
   at android.widget.LinearLayout.onLayout(LinearLayout.java:1051)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
   at android.view.View.layout(View.java:7320)
   at android.view.ViewRoot.performTraversals(ViewRoot.java:1162)
   at android.view.ViewRoot.handleMessage(ViewRoot.java:1882)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3701)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
   at dalvik.system.NativeStart.main(NativeStart.java)

无效指数3,大小为0 - 指标均crashlytics随机。
我使用与片段页眉和页脚的ListView。

Invalid index 3, size is 0 - indexes are Random in crashlytics. I am using ListView with header and footer in fragment.

onCreateView

mSearchBox = inflater.inflate(R.layout.search_box, mListView, false);
mListView.addHeaderView(mSearchBox, null, false);
mListView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();

我用头球为的ListView为的EditText ListView中搜索(故意,因为我想那是的EditText与滚动列表视图的内容)。同时,我用addFooterView用于显示加载器(列表中的下一个加载项时)。

I use header in ListView for EditText for searching in ListView (purposely because I want that EditText is scrollable with listview content). And also I use addFooterView for showing loader (when loading next items in list).

您可以看一下HeaderViewListAdapter线225(<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.4.4_r1/android/widget/HeaderViewListAdapter.java/#224\"相对=nofollow> grep的code ):

You can look at HeaderViewListAdapter line 225 (GrepCode):

public View getView(int position, View convertView, ViewGroup parent) {
// ...
// ... code
// ...

// Footer (off-limits positions will throw an IndexOutOfBoundsException)
return mFooterViewInfos.get(adjPosition - adapterCount).view;
}

编辑:
我发现similiar计算器线程,但它是不适合我有帮助:<一href=\"http://stackoverflow.com/questions/6950069/indexoutofboundsexception-with-listview\">Indexoutofboundsexception与列表视图
看起来Android的ListView控件是有点用ListView的页眉或页脚片段时窃听。

I have found similiar stackoverflow thread but It is not helpful for me: Indexoutofboundsexception with listview Looks like android ListView is a bit bugged when using header or footer in ListView with fragments.

推荐答案

我不得不设置列表视图空适配器之前,我正在收拾适配器:

I had to set null adapter on listview before I was clearing the adapter:

mListView.setAdapter(null);
mAdapter.clear();
mAdapter.notifyDataSetChanged();
mListView.setAdapter(mAdapter);

这篇关于HeaderViewListAdapter随机崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆