ListView中选定行的颜色消失 [英] ListView Selected Rows Colors Disappearing

查看:173
本文介绍了ListView中选定行的颜色消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有维护一个状态数组自定义的ListView活动(3个选择,默认为黑色,点击=绿色,第二次点击=红色)列表中的所有项目。基于用户选择的列表项/行的颜色发生变化,这样我就可以用于以后的数据标签项的颜色。现在,直到我滚动所选的项目关闭屏幕并返回活动视图,当他们的自定义颜色消失,一切工作正常。国家阵列仍包含了所有正确的信息,自定义色彩只是消失。我正在使用OnItemClickListener的ListView控件被点击项目时处理颜色的变化,但我猜这是不是最好的方法。什么是处理这个的最佳方式?

I have a custom ListView activity that maintains a state array (3 choices, default=black, one click=green, second click=red) for all items in the list. The color of the list item/row changes based on user selection, so I can use the color of the item for later data labelling. Now everything works fine until I scroll the selected items off the screen and return them to the active view, when their custom color disappears. The state array still contains all the correct information, the custom colors just disappear. I was using an OnItemClickListener on the ListView to handle the color changes when an item was clicked, but I'm guessing that's not the best approach. What would be the best way to handle this?

编辑:只是要清楚,我允许它有多种颜色多行选择

Just to be clear, I'm allowing selection of multiple rows which have multiple colors.

先谢谢了。

推荐答案

这可能是因为你有一个创建行的意见对你的适配器。为了更有效的适配器将重用不再在屏幕上可见行的看法。这减少了必须被保存在内存中的视图数。为了获得颜色,通过滚动它们关闭屏幕坚持你必须找到某种方式来存储每个项目应该是什么颜色,然后让您的适配器检查每个项目时,它构造的观点,并相应设置颜色。

It is probably because you have an Adapter that is creating the row views for you. To be more efficient Adapters will reuse row views that are no longer visible on the screen. This reduces the number of views that have to be kept in memory. In order to get the colors to persist through scrolling them off the screen you'd have to find some way to store what color each item should be on and then have your adapter check for each item when it constructs the view and set the color accordingly.

这篇关于ListView中选定行的颜色消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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