我有一个扩展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
发布评论