> > Hi everyone, > > I have a simple menu with 2 options: > > <menu xmlns:android="http://schemas.android.com/apk/res/android"> > <item android:id="@+id/congestion" > android:title="congestion event" > android:icon="@drawable/sign_congestion_small" /> > > > <item android:id="@+id/warning" > android:title="warning event" > android:icon="@drawable/sign_warning_small" /> > </menu> > > In onOptionItemSelected(), what do I need to compare item.getItemId() > to to figure out which item was selected? I am using getTitle for > niow, but I would prefer to use an id.
Menu IDs are like layout widget IDs, named by R.id: if (R.id.congestion==item.getItemId()) { // suggest a cold remedy } else if (R.id.warning==item.getItemId()) { // warn them about the side effects of the cold remedy } -- Mark Murphy (a Commons Guy) http://commonsware.com Android App Developer Books: http://commonsware.com/books.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---