android - 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.
解决方案
Recycler view reuses the same views for the different items. So you have to store selection state not only on the UI level.
推荐阅读
- amazon-web-services - 部署后如何在弹性 beantalk 上创建目录?
- microsoft-graph-api - 使用 Microsoft 图形 API 我想要用户个人资料照片
- python - ModuleNotFoundError:在我导入包或文件时,没有名为“---”的模块
- maven - 在 pom.xml 和 settings.xml 中定义的存储库,在 maven 构建期间优先
- android - 使用 Koin 时无法通过显式意图启动活动(Koincontext 已启动)
- android - 使用无障碍服务 android 10 记录通话
- java - Spring Sftp 使用入站适配器消息处理程序中的出站网关获取文件
- python - 如何使用 python-keycloak 登录 keycloak 后获取令牌
- reactjs - formik 渲染道具已被弃用,并将在未来版本中弃用
- etl - 在 tLogRow 中获取错误的日期