mobile - How to create preferences in Android? -
i have problem android settings. want create settings changing background color of activity. have do?
i have layout:
public class myapp extends preferenceactivity{ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } public void display(view view) { intent intent = new intent(this, display.class); startactivity(intent); } @override public boolean oncreateoptionsmenu(menu menu) { menuinflater menuinflater = getmenuinflater(); menuinflater.inflate(r.menu.menu, menu); return true; } public boolean onoptionsitemselected( menuitem item) { switch (item.getitemid()) { case r.id.menu_about: intent menu_about = new intent(this, about.class); startactivity(menu_about); return true; case r.id.menu_copyright: intent menu_copyright = new intent(this, copyright.class); startactivity(menu_copyright); return true; case r.id.menu_settings: // activity of settings return true; case r.id.menu_exit: finish(); return true; default: return super.onoptionsitemselected(item); } };
}
i want preference this:
http://i.stack.imgur.com/k2qa5.png
now, did understend me?
create sharedpreferences way
sharedpreferences settings = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = settings.edit(); editor.putstring("prefname", value); editor.commit();
get values way
sharedpreferences settings = getsharedpreferences(prefs_name, 0); string s = settings.getstring("prefname", ""));
the last statement means looking value of "prefname" , setting "" if nothing found.
hope helps
Comments
Post a Comment