在这里,当我快速滚动时,我遇到了“持有人”的问题,持有人位置得到更新(因为回收行为),一段时间后 onSuccess 被调用(因为它需要一些时间来获取数据),直到那时持有人位置已经改变并且持有人.mUserFullName.setText(user.getName()) 应用于错误的持有人位置。这只发生在我快速滚动时,如果我禁用回收然后它解决了问题,但我想要回收功能。
@Override
protected void onBindViewHolder(@NonNull PostVH holder, int position, @NonNull Post post) {
MyFirestoreDbRefs.getAllUsersCollection().document(post.getByUid())
.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
User user=documentSnapshot.toObject(User.class);
/*here i face a problem with 'holder' as i fast scroll,holder position gets updated
* (because of recycling behaviour) and after a while onSuccess gets called(as it takes some time for fetching data)
* until then the holder position already changed and holder.mUserFullName.setText(user.getName()) applied to wrong
* holder position */
holder.mUserFullName.setText(user.getName());
}
});
}