RecyclerView
コントロールの項目ビューをスクロールせずに更新しようとした後、アンドロイド開発で新規です。私の知る限り、項目はスクロール中にonBindViewHolder
event.here経由でリフレッシュされます。 notifyItemChanged
メソッドを使用してUIを更新しますが、ユーザーがスクロールするまで機能しません。データが変更された後、RecyclerViewはUIを更新しません
注:favoriteMatches
は私のデータソースではありません。 の中にonBindViewHolder
イベントがあります。アイテムがfavoriteMatches.contains(match)
の場合は、私はおしゃべりしていてfavアイテムとしてレンダリングしています。
call.enqueue(new Callback<AddRemoveFavoriteRequest.Response>() {
@Override
public void onResponse(Call<AddRemoveFavoriteRequest.Response> call, Response<AddRemoveFavoriteRequest.Response> response) {
AddRemoveFavoriteRequest.Response body = response.body();
Utilities.dismissProgressDialog(getActivity(),progressBar);
if(body.error == null){
if(add){
favoriteMatches.add(matchId);
}
else {
favoriteMatches.remove(matchId);
}
adapter.notifyItemChanged(absolutePosition);
Preferences.getDefaultPreferences().edit()
.putStringSet(Preferences.PREF_FAVORITES,favoriteMatches)
.apply();
}else{
Utilities.showSnackBar(getActivity(),recyclerView,body.error);
}
}
@Override
public void onFailure(Call<AddRemoveFavoriteRequest.Response> call, Throwable t) {
t.printStackTrace();
Utilities.dismissProgressDialog(getActivity(),progressBar);
}
});
「absolutePosition」とは何ですか? –
'adapter.notifyDataSetChanged()'を使ってみてください。それでも問題がなければ、データに問題があります。それがうまくいけば、 'absolutePosition'が正しいかどうかを確認してください。 –