I am a beginner to android applications and java, basically I am a PHP developer.
I\'ve a project for a tab+swipe application,
create a menu xml file for menu_a.xml and menu_b.xml in the res/menu folder.
To create a option menu for the current Fragment displayed, add setHasOptionsMenu(true); to the Fragment onCreate() method.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
Then you must inflate the corresponding option menu (menu_a.xml or menu_b.xml) by override the onCreateOptionsMenu() method.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_a, menu);
super.onCreateOptionsMenu(menu, inflater);
}
For handling menu selections override the onOptionsItemSelected()
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_search:
//do something
return true;
case R.id.menu_item_share:
//do something
return true;
}
return super.onOptionsItemSelected(item);
}
see Creating an Options Menu: http://developer.android.com/guide/topics/ui/menus.html for more details.