Save & restore dialog state on screen rotate

This commit is contained in:
Roumen Georgiev 2018-07-17 12:01:21 +03:00 committed by GitHub
parent b689aff02d
commit cd4e7c2d4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -148,6 +148,11 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
setCancelable(true);
getDialog().setCanceledOnTouchOutside(false);
if (savedInstanceState != null) {
// log.debug("savedInstanceState in onCreate is:" + savedInstanceState.toString());
editInsulin.setValue(savedInstanceState.getDouble("editInsulin"));
editTime.setValue(savedInstanceState.getDouble("editTime"));
}
return view;
}
@ -156,6 +161,18 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
return value > 0 ? "+" + formatted : formatted;
}
@Override
public void onSaveInstanceState(Bundle insulinDialogState) {
insulinDialogState.putString("message", "This is my message to be reloaded");
insulinDialogState.putBoolean("startEatingSoonTTCheckbox", startEatingSoonTTCheckbox.isChecked());
insulinDialogState.putBoolean("recordOnlyCheckbox", recordOnlyCheckbox.isChecked());
insulinDialogState.putDouble("editTime", editTime.getValue());
insulinDialogState.putDouble("editInsulin", editInsulin.getValue());
insulinDialogState.putString("notesEdit",notesEdit.getText().toString());
log.debug("Instance state saved:"+insulinDialogState.toString());
super.onSaveInstanceState(insulinDialogState);
}
@Override
public synchronized void onClick(View view) {
switch (view.getId()) {