除非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();
}
});
}