ListView IndexOutOfBoundsException [英] ListView IndexOutOfBoundsException

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

问题描述

我在我的适配器中收到有关 IndexOutOfBoundsException 的崩溃报告,它从未在我的设备上发生过,所以我不知道具体情况.

i"m getting crash reports on IndexOutOfBoundsException inside my adapter , it was never happen on my device so i don't know the scenario .

在我的 getView 上它崩溃 (itemlist.get(position)):

on my getView it crash (itemlist.get(position)):

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

Object i = itemlist.get(position);

当然我会覆盖 getcount ,正如我提到的,它从来没有发生在我身上,但我有时会收到发生在 usersaa 上的报告

and of course i override getcount , as i mention it was never happen to me but i get reports that is happen to usersaa sometimes

public int getCount() {
    return itemlist.size();
}

任何想法怎么可能?以及如何预防?

any ideas how could it be ? and how to prevent it ?

推荐答案

你应该使用 parent 代替 itemlist 从列表中获取数据.

you should use parent in place of itemlist to get data from list.

Object item = parent.getItemAtPosition(position);

String text=item.toString();

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

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