android - Store & Retrieve Button State using shared preference -


i making application has 2 button news , data.

if pressed news button display news in listview , same data.

the problem want store button state sharedpreference means, once selected news button, after exit when again run application want news button pressed , display news data listview.

how can implement ?

i using code not ..

    sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);      editor edit = preferences.edit();     edit.putstring("pref_empid", _empid);     edit.putstring("pref_usertype", _usertype);     edit.commit(); 

sorry bad english need thank in advance

at time of clicking news or data save preferencw value following:

sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);   editor edit = preferences.edit(); edit.putstring("which_list", "news"); // when clicking news button //  edit.putstring("which_list", "data"); // when clicking data button edit.commit(); 

when ever start activity, check shared preference value of which_list following:

string which_list = preferences.getstring("which_list", ""); 

now, compare:

if(which_list.equals("news")) {     //    load  news  list } else if(which_list.equals("data")) {     //    load  other  data  list } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -