android - how to Save value in Shared Preference and set in spinner -


i know question has been asked many times don't understand how set because new in android.

i have tried this:

1. saved prefrence

2. use this

here code:

sharedpreferences.editor editor = sharedpreferences.edit(); string gender = gender.get(i).tostring(); editor.putstring(gender1, gender); editor.commit();  list = new arraylist<string>();     list.add("male");     list.add("female");      arrayadapter<string> dataadapter = new arrayadapter<string>(getactivity(),             android.r.layout.simple_spinner_item, list);     dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);     // int selectedposition = gender.getselecteditemposition();     gender.setselection(sharedpreferences.getint("gender1", -1));     list.indexof(sharedpreferences.getstring(gender1, "gender1"));     gender.setadapter(dataadapter); 

edit:-
want set stored value in spinner stored in preference.

please me.

i want store in value when user saves account detail

thank in advance.

self solution:

fgender= sharedpreferences.getstring(gender1, "gender1");     if(fgender.equals("female")){         gender.setselection(1);     }else     {         gender.setselection(0);     } 

again, thank answers.

you can save like

sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(context);     sharedpreferences.editor editor = sharedpreferences.edit();     editor.putint("gender1", -1);     editor.apply(); 

and retrieve saved value preferences

    sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(context);     return sharedpreferences.getint("gender1", 0); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -