在onBindViewHolder RecyclerView Firebase适配器中检索用户uid详细信息| FirebaseUI | Android,Java

问题描述 投票:0回答:1

这里,我快速滚动时遇到“持有人”问题,持有人位置被更新(由于回收行为),并且在一段时间后被调用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 DBUsers Collection Structure in DB

android android-recyclerview recycler-adapter firebaseui
1个回答
0
投票

以下解决方案在某些情况下可能会起作用:

© www.soinside.com 2019 - 2024. All rights reserved.