1

I have a various EditText fields in my android app, what I want is on "Save" button click it should stored the entered value in sharedpreference and display it in a list view in another activity.

How would I do that?

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
  • 1
    You can make a model class and store object in shared preference usign gson. refer this answer https://stackoverflow.com/a/18463758/9792247. – Prayag Gediya Aug 23 '19 at 04:58
  • 1
    I would suggest not to use sharedpref if you are not going to use them again. as per my understanding you want those values in next activity and these value will change so pass them via intent. – akshay_shahane Aug 23 '19 at 04:59

1 Answers1

0

If you don't need the content of your editText after the application is closed, there is no need for SharedPreferences.just pass it using Intent like this.

EditText editText = findViewById(R.id.yourEditTextId);
Intent intent= new Intent();
intent.putExtra("key",editText.getText());
startActivity(intent);

In the other activity, you can get your editText value like this

String editTextValue=getIntent().getStringExtra("key");

If you have multiple EditText, you can use Room Database to store your Data which allows you to access it throughout the application.

tariku tsegaye
  • 101
  • 1
  • 2