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 <faberfe...@gmail.com > <mailto:faberfe...@gmail.com>> 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. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 2.0 Published! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---