Anonymous
Anonymous

Reputation: 323

Android save EditText text

I have a school planer app and I want to save the classes that are written in an EditText object. The problem is, the EditTexts are empty when I close the app and then open it again, and even when I press back. This may be a noob question, but I'm a beginner and I need help. Please answer quickly...

Upvotes: 0

Views: 175

Answers (1)

Shabbir Dhangot
Shabbir Dhangot

Reputation: 9141

for saving edittext text you need to store the text into storage.

android support storage like

  1. Database
  2. Shared Preferences

For your problem you need to store your Edittext text into the storage when you change value.

And when you open it again you need to retrieve from the storage.

For you best option will be shared preferences. For more Go with This Example . This will make you understand save and retrieve shared preferences.

Short Example

Store Data

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
editor = pref.edit();
editor.putString("first_edittext", "value");
editor.commit();

Retrieve Data

SharedPreferences pref = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext());
pref.getString("first_edittext", "");

Upvotes: 1

Related Questions