You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 8, 2025. It is now read-only.
Steven Lewi edited this page Apr 9, 2015
·
1 revision
@OptionMenu can be used to automatically inflate option menu of your Activities and Fragments. Put this Annotation on the top of Activity/Fragment class. @OnMenuItemSelected can be used to bind menu item click/select listener (onOptionsItemSelected(MenuItem item))
See this example below.
Common Activity Menu Inflater
publicclassMainActivityextendsActionBarActivity {
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@OverridepublicbooleanonCreateOptionsMenu(Menumenu) {
// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.menu_main, menu);
returntrue;
}
@OverridepublicbooleanonOptionsItemSelected(MenuItemitem) {
// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.intid = item.getItemId();
//noinspection SimplifiableIfStatementif (id == R.id.action_settings) {
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
}