适配器是否在第二个notifyDataSetChanged上刷新?

时间:2018-06-08 18:56:23

标签: android android-recyclerview recycler-adapter quickblox quickblox-android

除非notifyDataSetChanged执行两次,否则适配器不会刷新! 但是当我在调试器中跟踪它时它完美无缺! 这个问题只发生在 sendRequest 方法上,它在其他方法上运行得非常好!

      if (friendListHelper.isFriendRequestAlreadySent(user.getId())) {
            holder.addFriendBtn.setText("Cancel Request");
            holder.addFriendBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    cancelRequest(view, user, position);
}
           });
        } else if (friendListHelper.isFriend(user.getId())) {
            holder.addFriendBtn.setText("Unfriend");
            holder.addFriendBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    deleteFriend(view, position, user);
                }
            });
        } else {
            holder.addFriendBtn.setText("Add Friend");
            holder.addFriendBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    sendRequest(user, view, position);
                }
            });
        }
    }


     private void deleteFriend(final View view, final int position, QBUser user) {
            friendListHelper.removeFriend(user, new QBEntityCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid, Bundle bundle) {
                    notifyItemChanged(position);
                }
            });
        }

        private void cancelRequest(final View view, QBUser user, final int position) {
            friendListHelper.cancelFriendRequest(user.getId(), new QBEntityCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid, Bundle bundle) {
                    notifyItemChanged(position);
                }

        }

        private void sendRequest(final QBUser user, final View view, final int position) {
            friendListHelper.sendFriendRequest(user, new QBEntityCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid, Bundle bundle) {
                    notifyDataSetChanged();
                }
            });
        }

0 个答案:

没有答案