Android: TabActivity, Creating Menu
i have created 3 tabs using the TabActivity. The class declaration is like this.
public c开发者_如何学Golass ABTM extends TabActivity {
........ some code ..........
}
now i want to create a Menu with three menu items. but the problem is that the
**@Override public boolean OnCreateOptionsMenu(Menu menu){
}**
gives error. It says that i should remove the @Override. When i remove the @Override the error is gone and the application runs fine but pressing the menu button does nothing.
What am i doing wrong here?
Looks like it's a case issue. The method name should be onCreateOptionsMenu
with a lower case first letter. The purpose of @Override
is specifically to warn you if the method that you are attempting to override does not exist in the superclass. By removing @Override
you are ignoring the cause of the problem and declaring a differently named method, which is why it doesn't get invoked.
Make sure you have Menu imported. Whenever I get this error when overriding methods, it's because the type of one (or more) parameters hasn't been imported. Unfortunately, the result is that Eclipse can't make sense of what you're trying to override and throws an error stating this instead of first throwing an error saying it doesn't know what "Menu" is.
精彩评论