android - Display and edit the value stored in the SharedPreferences -


help please, i'm bit lost, new , trying learn. want store 3 names , phone numbers in sharedpreferences , display them in individual textviews user can edit name , phone number , press number call number.

what have far is:

public void setwardenname(context context, string key, string value) {             sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);             sharedpreferences.editor editor = preferences.edit();             editor.putstring(getstring(r.string.), name);             editor.apply();     }     public void getwardenname(context context, string prefkey) {         sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);         string name = preferences.getstring("name", "");         if(!name.equalsignorecase(""))         {             name = name;         }     } 

and on activity screen have first texview called:

android:id="@+id/textview2" going first name.

so i'm lost, appreciated.

i set warden key name , depends on if want change that. and, assume in same class since using 'this' in

sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this); 

so here is..

private void setwarden(string value) {     sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);     editor editor = sharedpref.edit();     editor.putstring("warden", value);     editor.commit(); }   private string getwarden() {     sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);     string name = sharedpref.getstring("warden", "");     if(!name.equalsignorecase(""))         {         return name;                     }     return ""; } 

and in textview can like:

textview tv = (textview) findviewbyid(r.id.textview2); tv.settext(getwarden()); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -