How to prevent editing text from a text file if it was restored from a saved copy?

I have an activity that contains and shows several fragments.

When I enter the fragment again, it automatically fills the text in all editTexts. The same text for all fields.

Example:

Open the fragment and fill the text in two text editors:
CustomEditText1: [______]
CustomEditText2: [_acb__]
CustomEditText3: [_qwe __]

Press the back button and re-enter the fragment
CustomEditText1: [_qwe__]
CustomEditText2: [_qwe__]
CustomEditText3: [_qwe __]

These are my rewritten methods in the snippet:

public AddBookingFragment() {
    // Required empty public constructor
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    tabsActivity = (TabsActivity) getActivity();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_add_booking, container, false);

    lastNameEditText = (NASEditText) view.findViewById(R.id.nas_add_booking_last_name);
    pnrEditText = (NASEditText) view.findViewById(R.id.nas_add_booking_pnr);

    addButton = (NASButton) view.findViewById(R.id.nas_add_booking_add_button);
    scanButton = (NASButton) view.findViewById(R.id.nas_add_booking_scan_button);

    confirmationBox = (LinearLayout) view.findViewById(R.id.nas_add_booking_confirmation_box);
    confirmationText = (NASHeaderAndSubtext) view.findViewById(R.id.nas_add_booking_confirmation_text);
    confirmationBox.setVisibility(View.GONE);

    bindButtons();

    FontHelper.setFont(container, tabsActivity);
    return view;
}

, editText OnTextChanged.

stacktrace : Stacktrace
(NASEditText - )

/:

  • ///editText ?
  • ?
+4
2

!

SaveEnabled true editTexts Android.


:
setSaveEnabled(false);
editText.

, , ...

+5

, :

@Slugge:
onSaveInstanceState editText / , .

+1

Source: https://habr.com/ru/post/1673994/


All Articles