首页 > 解决方案 > Android Recyclerview same item layout changes after certain number of items

问题描述

I want to give the possibility to select multible items in a recyclerview. If the users clicks on a item I do following to change the background color of the item:

relativeLayout = viewHolder.rL;
relativeLayout.setBackgroundColor(Color.rgb(224, 224, 224));

this works fine, but after 10 items the item is also grey. If I change setItemViewCacheSize() to for example 100 this problem doesn't occur. But I am not shure if this is the right way.

标签: androidandroid-recyclerviewandroid-viewholder

解决方案


Recycler view reuses the same views for the different items. So you have to store selection state not only on the UI level.


推荐阅读