Android的列表视图viewholder。什么时候使用它,什么时候不什么时候、视图、列表、使用它

2023-09-05 01:41:36 作者:离愁▍trust

我有一个自定义列表适配器一个ListView。在getView()方法,现在用的是ViewHolder'模式'如图所示的API演示的ListView14.java。当我第一次呈现清单似乎正确加载。但是,我快到的问题是,当我滚动列表,我看到的数据列表显示在错误的行(即一个TextView应该是在第10行是显示在第2行,例如)。然而,当我不使用viewholder,而是调用findViewById()每一次,则列表视图呈现正常。

解决方案   

不过,我快到的问题是   当我滚动列表,我是   看到数据的列表中显示出来   错了行(即一个TextView   这应该是在第10行中显示出来   在例如第2行)。

最有可能的,你是不正确的回收行,使得 ViewHolders 你操纵是不正确的药粥行要返回。

下面是从我的书一个进入更多的行回收一个免费的摘录 - 也许这将有助于您确定事情会出错。

I have a ListView with a custom list adapter. In the getView() method, am using the ViewHolder 'pattern' as shown in the API Demos for ListView14.java. When i first render the list it seems to load correctly. However, the issue i'm running into is that when i scroll the list, i'm seeing the data for the list show up in the wrong rows (i.e. a TextView that should be in row 10 is showing up in row 2 for example). However, when I do not use the viewholder, and instead call findViewById() every time, then the list view renders correctly.

解决方案 Android手机端有哪些是目录树视图的文件管理器 就是图上那样,图上的是X plore,目前我唯

However, the issue i'm running into is that when i scroll the list, i'm seeing the data for the list show up in the wrong rows (i.e. a TextView that should be in row 10 is showing up in row 2 for example).

Most likely, you are improperly recycling your rows, such that the ViewHolders you are manipulating are not the right ones for the row you are returning.

Here is a free excerpt from one of my books that goes into more about row recycling -- perhaps it will help you identify where things are going wrong.

 
精彩推荐
图片推荐