user interface - Android item group android:checkableBehavior="single" -
i want programmatically set radio button of group according changing program status.
the xml file this:
<item android:id="@+id/silent_mode" android:title="@string/silent_mode" > <menu> <group android:checkablebehavior="single" android:id="@+id/silent_on_off"> <item android:id="@+id/silent_mode_on" android:checked="false" android:title="@string/silent_mode_on_text" /> <item android:id="@+id/silent_mode_off" android:checked="true" android:title="@string/silent_mode_off_text" /> </group> </menu> </item>
and wish update slient_mode_on or slient_mode_off according state of variable, let boolean variable called issilentmode. isslientmode variable change on fly. there background service check every 5 minutes. if isslientmode turn true, want set slient_mode_on.setselected(true), else set false.
i tried set menuitem, there no response @ all. item keep @ same state user previous selection, , not update according program change.
how handle this?
public static void updatesilentmodecheckbox() { if (mainmenu!=null) { menuitem itemon = mainmenu.finditem(r.id.silent_mode_on); menuitem itemoff = mainmenu.finditem(r.id.silent_mode_off); log.i("mainactivity", itemon.ischecked() + " " + issilentmode + " "); if (itemon.ischecked() && issilentmode) { // silentmodeon, itemonchecked, donothing } else if (itemon.ischecked() && !issilentmode) { itemoff.setchecked(true); itemon.setchecked(false); } else if (!itemon.ischecked() && issilentmode) { itemon.setchecked(true); itemoff.setchecked(false); } else if (!itemon.ischecked() && issilentmode) { // donothing } log.i("mainactivity", itemon.ischecked() + " " + issilentmode + " "); } }
i found status of itemon , itemoff never updated.
Comments
Post a Comment