Hey I have a really stupid problem and I can't figure out why it is not working as expected. So I have a MultiFragment layout (each one has some different questions) using viewpager and FragmentStatePagerAdapter. When I open the screen that hosts all these fragments I am trying to restore the previous state (marking all answered questions) using a network call. However it seems that if my Fragment is not visible to the user it can't update the checked state of the radio button / checkboxes.
Does anybody know what I can do to achieve the wished behavior?
Cheers and thanks in advance!
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
presenter.restoreAnswersFromPreviousSession(questionId);
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisible()) {
if (isVisibleToUser) {
presenter.restoreAnswersFromPreviousSession(questionId);
Log.d("Fit", "My Fragment is visible");
} else {
Log.d("Fit", "My Fragment is not visible");
}
}
}
Here I restore the state (called after the request is successful)
previousReplies = repliesToRestore;
for (QualityReportReply reportReply : repliesToRestore) {
int id = reportReply.id();
switch (id) {
case 201: {
boolean tooThin = (boolean) reportReply.value();
if (tooThin) {
materialTooThinGroupYes.setChecked(true);
} else {
materialTooThinGroupNo.setChecked(true);
}
break;
}
case 202: {
boolean tooThick = (boolean) reportReply.value();
if (tooThick) {
materialTooThickGroupYes.setChecked(true);
} else {
materialTooThickGroupNo.setChecked(true);
}
break;
}
case 203: {
boolean drawingThreads = (boolean) reportReply.value();
if (drawingThreads) {
materialDrawThreadsGroupYes.setChecked(true);
} else {
materialDrawThreadsGroupNo.setChecked(true);
}
break;
}
case 204: {
boolean flyingThreads = (boolean) reportReply.value();
if (flyingThreads) {
materialFlyingThreadsGroupYes.setChecked(true);
} else {
materialFlyingThreadsGroupNo.setChecked(true);
}
break;
}
case 205: {
boolean knots = (boolean) reportReply.value();
if (knots) {
materialKnotsGroupYes.setChecked(true);
} else {
materialKnotsGroupNo.setChecked(true);
}
break;
}
setChecked()
and the fragment where this is set is not visible – Hydraulic