On Mon, Feb 23, 2009 at 7:24 AM, Mark Murphy <[email protected]> wrote: > > Faber Fedor wrote: >> I guess this one is too advanced for the beginner's group, so I'll ask >> it here: >> >> On Mon, Feb 16, 2009 at 9:20 PM, Faber Fedor <[email protected] >> <mailto:[email protected]>> wrote: >> >> On my map menu I've got two menuitems: "Map View" and "Satellite >> View". I'm sure you can figure out what they do. :-) I want to >> push "Map View" and have the "Satellite View" menuitem disappear and >> vice-versa. I thought the following code was the obvious way to do >> it, but my map_menuitem and satellite_menuitem are both set to >> null. Yes, the R.id's do exist and Eclipse is happy with all the >> code. I don't see why this shouldn't work, 'cept it don't. Suggestions? >> >> <CODE> >> public boolean onOptionsItemSelected(MenuItem item) { >> >> Intent i; >> >> switch(item.getItemId()) { >> case R.id.satellite_menuitem: >> MenuItem map_menuitem = (MenuItem) >> findViewById(R.id.map_menuitem); > > MenuItems aren't Views. I mean that literally: MenuItem is an interface, > not a subclass of View. > > Hence, to find a MenuItem, you don't call findViewById(). Instead, you > need to hold onto the Menu you populated in onCreateOptionsMenu() and > call findItem() on it.
Or, in onCreateOptionsMenu(), you could create only the menu items you need for the particular mode you're in. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

