java - DialogPreference setSummary() -
i have custom preference displaying timepicker dialog when clicked. want set summary preference when value choosed displaying chosen time. how done? don't understand how use setsummary(charsequence) method.
the custom preference:
public class timepreference extends dialogpreference { final calendar c = calendar.getinstance(); int hour = c.get(calendar.hour_of_day); int minute = c.get(calendar.minute); private timepicker timepicker; public timepreference(context context, attributeset attributes) { super(context, attributes); setpersistent(false); } @override public void onbinddialogview(view view) { super.onbinddialogview(view); timepicker = (timepicker) view.findviewbyid(r.id.preftimepicker); timepicker.setcurrenthour(getsharedpreferences().getint(getkey() + ".hour", hour)); timepicker.setcurrentminute(getsharedpreferences().getint(getkey() + ".minute", minute)); timepicker.setis24hourview(dateformat.is24hourformat(timepicker.getcontext())); } @override protected void ondialogclosed(boolean oktosave) { super.ondialogclosed(oktosave); if (oktosave) { timepicker.clearfocus(); sharedpreferences.editor editor = geteditor(); editor.putint(getkey() + ".hour", timepicker.getcurrenthour()); editor.putint(getkey() + ".minute", timepicker.getcurrentminute()); editor.commit(); // here should setsummary() method, maybe? } } }
the main activity:
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getfragmentmanager().begintransaction().replace(android.r.id.content, new prefsfragment()).commit(); } }
use following lines in dialogpreference constructor
settitle("your preference name goes here"); setsummary("your summary goes here")
Comments
Post a Comment