getItemViewType位置始终为0 [英] getItemViewType position always 0

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

问题描述

我有一个扩展BaseAdaptor并覆盖 getItemViewType(int position)函数的类.当我交换游标或通知数据集更改时,为位置传递的值始终为0.但是,如果将调试点放入getItemViewType中并调用getCount,则返回的值为4.类似地,调用getItem(0),来自同一调试点的getItem(1),getItem(2)和getItem(3)均返回有效结果.

I have a class that extends BaseAdaptor and overrides the getItemViewType(int position) function. When I swap the cursor or notify the data set change, the value being passed in for position is always 0. However if I put a debug point in getItemViewType and call getCount, the value returned is 4. Similarly, calling getItem(0), getItem(1), getItem(2) and getItem(3) from the same debug point all return valid results.

有什么想法为什么位置不会重复[0,1,2,3]?

Any ideas why position doesn't iterate though [0,1,2,3]?

推荐答案

可能是因为 getTypeCount 返回"1"-因此实际上不需要遍历位置"-Android假定所有视图类型都是一样.

Probably because getTypeCount returns "1" - so there's no need to actually iterate through "position" - Android assumes all view types are the same.

您可能应该重写该方法:

You should probably Override that method:

public int getViewTypeCount() {
    return 1;
}

但是首先,请确保您知道它的作用.仅当您具有不同的类型数据,而没有不同的时,此功能才有用.看到这篇文章:

But first, be sure that you know what it does. It's only useful if you have different types of data, not different values. See this post:

ArrayAdapter的getViewTypeCount和getItemViewType方法

这篇关于getItemViewType位置始终为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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