Android的适配多getView [英] Android Adapter multiple getView

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

问题描述

我看了一下getView的问题被多次调用,所有的答案。但是,我不觉得我的问题的解决方案。

i have read about the issue of getView called multiple times and all the answers. However, i don't find a solution for my problem.

我有一个列表,其中列有两种状态:读或不。好吧,我想看到​​的第一次的项目有不同的颜色,当我滚动列表,他们改变自己的颜色读状态。

I have a list where rows have two states: read or not. Well, i want to the items seen for first time have a different color and when i scroll the list, they change their color to "read state".

为了做到这一点,在我的适配器的方法getView我设置一个字段isRead当行该项目是画。但问题是如下:因为该方法getView多次调用的字段被标记为已读和当该列表显示在屏幕看来好像它已经被读

In order to do this, in the method getView of my adapter i set a field isRead when the row for that item is painted. But the problem is the following: since the method getView is called multiple times the field is marked as read and when the list is shown in the screen it appears as if it had already been read.

任何想法来解决这个问题呢?

Any idea to fix this problem?

感谢

推荐答案

我假定你的意思getView的问题,要求同样的观点多次。

I assume you mean the issue of getView requesting the same view several times.

的ListView这样做是因为它需要获得测量结果不同的原因的看法(滚动条大小,布局等)

ListView does this because it needs to get measurements for the views for different reasons (scrollbar size, layout, etc)

这个问题通常可避免不使用你的列表视图的WRAP_CONTENT属性。

This issue can usually be avoided by not using the "wrap_content" property on your listview.

除此之外,利用getView以确定是否认为已经显示仅仅是一个坏主意。 ListView中有很多优化,惹的顺序getView被称为上的每一行,所以没有办法知道会发生什么事,你的应用程序将开始呈现出奇怪的行为。

Other than that, using getView to determine if a view has been displayed is simply a bad idea. ListView has many optimizations that mess with the order getView is called on for each row, so there is no way to know what will happen and your app will start showing odd behavior.

尽量避免视图和数据比视图的概念作为数据的显示等之间的任何关系。

Try to avoid any relationship between the view and the data other than the concept of view as a display of that data.

相反,在你listactivity一些工作线程或事件侦听器观看的量列表中的项目已被显示给用户的列表中,更新数据,并调用dataSetChanged在适配器上。

Instead, have some worker thread or event listener in your listactivity watch the list for which items in the list have been displayed to the user, update the data, and call dataSetChanged on your adaptor.

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

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