【发布时间】:2020-04-28 11:44:00
【问题描述】:
在这里,当我快速滚动时,我遇到了“持有人”的问题,持有人位置得到更新(因为回收行为),过了一会儿 onSuccess 被调用(因为它需要一些时间来获取数据) 在此之前,持有人位置已经改变,并且 holder.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());
}
});
}
Post Collection Structure in DB Users Collection Structure in DB
【问题讨论】:
标签: android android-recyclerview firebaseui