简体   繁体   English

在视图滚动条上限制OnBindViewHolder

[英]Restrict OnBindViewHolder on View scroll

I have created a recycler view leaderboard adapter to display people names with their ranks. 我创建了一个回收者视图排行榜适配器,以显示人员姓名及其等级。 When I scroll down and up the serial no changes and it gets messed up. 当我上下滚动序列时,没有任何变化,并且混乱了。 It's because the onBindViewHolder is being called again for the integer which sets the serial number. 这是因为onBindViewHolder被再次调用设置序列号的整数。

How do I stop the method while scrolling? 滚动时如何停止该方法? Is there any way? 有什么办法吗?

Your thinking is wrong here. 您的想法在这里是错误的。 onBindViewHolder is expected to be called when you scroll and you shouldn't try to stop it from being called. 滚动时应调用onBindViewHolder并且不应尝试阻止其被调用。

The problem here is that you do the counting in onBindViewHolder . 这里的问题是您要在onBindViewHolder进行计数。 This is wrong. 错了 You are only supposed to bind the data to your views here, just as the method name implies. 正如方法名称所暗示的那样,您只应在此处将数据绑定到视图。 Don't change your data in onBindViewHolder and the problem will go away. 不要在onBindViewHolder更改您的数据,问题将会消失。 Instead, prepare the data before sending it to the adapter. 相反,请准备数据,然后再将其发送到适配器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM