I am using Recycler view to display a list of elements. Each row has a button on it when we click it status changes and its background color. I am calling notifyDataSetChanged() once the status is updated but recyclerView is not getting refreshed.
else if (allGoals.getStatus() == WorkoutCashConstants.GOALS_ACHIEVE) {
boolean networkStatus = checkNetworkStatus();
if (networkStatus) {
dateFormat = new SimpleDateFormat("yyyy-MM-dd");
if (DATE_ACCESS == null) {
currentTimeStamp = dateFormat.format(new Date());
} else {
currentTimeStamp = DATE_ACCESS;
}
progDialog = ProgressDialog.show(CompanyGoals_AllGoals_Fragment.this.getActivity(), "", "Goal Progress Recorded");
progDialog.setCancelable(true);
AchieveGoals achieveGoals = new AchieveGoals(Integer.parseInt(allGoals.getGoalID()), currentTimeStamp);
Call<AchieveGoals> achieveGoalsCall = apiModule.achieveGoal(achieveGoals);
achieveGoalsCall.enqueue(new Callback<AchieveGoals>() {
@Override
public void onResponse(Response<AchieveGoals> response, Retrofit retrofit) {
progDialog.dismiss();
if (response.isSuccess()) {
progDialog.dismiss();
goalsAchieved = response.body();
if (goalsAchieved.getAppStatusCode() == WorkoutCashConstants.SUCCESS_API) {
realm = Realm.getInstance(getContext());
realm.beginTransaction();
AllGoalsDB goalsDB = realm.where(AllGoalsDB.class)
.equalTo("goalID", allGoals.getGoalID()).findFirst();
CompeletedDatesDB compeletedDatesDB = realm.createObject(CompeletedDatesDB.class);
compeletedDatesDB.setCompletedDate(currentTimeStamp);
goalsDB.getCompeletedDatesDBs().add(compeletedDatesDB);
realm.commitTransaction();
UserInfoDB userInfoDB = realm.where(UserInfoDB.class)
.equalTo(WorkoutCashConstants.
COLUMN_USER_ID, userId)
.findFirst();
if (userInfoDB != null) {
realm.beginTransaction();
userInfoDB.setSweatPoints(goalsAchieved.getData().getSweatPoints());
realm.commitTransaction();
}
realm.close();
notifyDataSetChanged();
}
}