且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ListView中选定行的颜色消失

更新时间:2023-09-18 23:33:04

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

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.