棉绒错误“不要将位置视为固定;只能立即使用..." [英] Lint error "Do not treat position as fixed; only use immediately..."
本文介绍了棉绒错误“不要将位置视为固定;只能立即使用..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为开源库做贡献,并且出现了lint错误不要将位置视为固定;只能立即使用,并调用holder.getAdapterPosition()稍后再查找" :
I'm contributing to open source library and got lint error "Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later" for this code:
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
mAdapter.onBindViewHolder(holder, position);
if (!isFirstOnly || position > mLastPosition) {
for (Animator anim : getAnimators(holder.itemView)) {
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = position;
} else {
ViewHelper.clear(holder.itemView);
}
}
我检查过,是因为该位置已保存以备将来使用.对于图书馆创建者来说,这是一个问题,为什么他们需要这种逻辑.但是,当我将职位的用法更改为用法holder.getAdapterPosition()
时,问题消失了:
I've checked that it is because the position is saved for the future use. It is a question to library creator why they need this logic. But issue disappeared when I change the usage of the position to the usage holder.getAdapterPosition()
:
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
mAdapter.onBindViewHolder(holder, position);
if (!isFirstOnly || holder.getAdapterPosition() > mLastPosition) {
for (Animator anim : getAnimators(holder.itemView)) {
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = holder.getAdapterPosition();
} else {
ViewHelper.clear(holder.itemView);
}
}
我认为从概念上讲它变化不大,但现在皮棉很满意.为什么?
I assume that conceptually it didn't change much but lint is satisfied now. Why?
推荐答案
查看全文