Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplays editText value sharedpreference save
    primarykey
    data
    text
    <p>I have 3 EditText. When i enter some text or some numbers then click save button it goes to another Activity. Again come back on editText, the values are gone and set to android:text="value". I need to display the values after typing in editText box.</p> <p>code:</p> <pre><code>et=(EditText)findViewById(R.id.pieces); et1=(EditText)findViewById(R.id.portions); et2=(EditText)findViewById(R.id.ml); save=(Button)findViewById(R.id.submit_data); save.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub SharedPreferences preferences = getApplicationContext().getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = preferences.edit(); editor.putString("text1",pieces.getText().toString()); editor.putString("text2",portions.getText().toString()); editor.putString("text3",ml.getText().toString()); editor.commit(); String oneedit= preferences .getString("text1", ""); String twoedit= preferences .getString("text2", "" ); String thirdedit= preferences .getString("text3", "" ); pieces.setText(oneedit); portions.setText(twoedit); ml.setText(thirdedit); /* SharedPreferences.Editor editor = preferences.edit(); editor.putString("text1",pieces.getText().toString()); editor.putString("text2",portions.getText().toString()); editor.putString("text3",ml.getText().toString()); editor.commit(); Intent intent=new Intent(Activity.this,Activity1.class); startActivity(intent); } }); </code></pre> <p>If i use below code, it loads the saved values:</p> <pre><code>edit.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); //edittext.setText(sharedpreference.getString(KEYNAME, "No value Stored")); et.setText(preferences.getString("text1", " ")); et1.setText(preferences.getString("text2", " ")); et2.setText(preferences.getString("text3", " ")); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload