getItemViewType位置始终为0

编程入门 行业动态 更新时间:2024-10-10 09:17:08
本文介绍了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

本文发布于:2023-11-16 03:55:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   getItemViewType

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!