Friday 15 February 2013

android - Use sharedpreferences -



android - Use sharedpreferences -

i wrote code snippet alter background color of linearlayout selecting radiobuttons , main color of layout white , but want maintain 1 of these radiobuttons(their color) when checked , after closing app turns main color. how can utilize shared preference this?

my .java file:`

public class setting extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.setting); final linearlayout ll=(linearlayout) findviewbyid(r.id.linearlayout); final radiobutton radio_red = (radiobutton) findviewbyid(r.id.radio_red); final radiobutton radio_yellow = (radiobutton) findviewbyid(r.id.radio_yellow); radio_red.setonclicklistener(new onclicklistener() { public void onclick(view v) { ll.setbackgroundcolor(color.red); } }); radio_yellow.setonclicklistener(new onclicklistener() { public void onclick(view v) { ll.setbackgroundcolor(color.yellow); } }); } }

`

i have nice illustration here:

android shared preferences

you're going write preference , read preference. easy peasy.

android sharedpreferences

No comments:

Post a Comment