Android, How to create option Menu

vishesh chandra picture vishesh chandra · Jun 22, 2011 · Viewed 203k times · Source

Here I tried to make option menu, but menu is not displaying on screen, so please guide me where am I doing mistake...

MenuTest.java

public class MenuTest extends Activity {
   @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater=getMenuInflater();
    inflater.inflate(R.menu.more_tab_menu, menu);
    return super.onCreateOptionsMenu(menu);

}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId())
    {
    case R.id.feeds:
        break;
    case R.id.friends:
        break;
    case R.id.about:
        break;
    }
    return true;
}
}

And my XML file is more_tab_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/feeds"
    android:title="Feeds"/>
<item
    android:id="@+id/friends"
    android:title="Friends"/>
<item
    android:id="@+id/about"
    android:title="About"/>
</menu>

Please guide me,

Answer

DEVANG SHARMA picture DEVANG SHARMA · Jun 22, 2011
public class MenuTest extends Activity {

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.more_tab_menu, menu);

        // return true so that the menu pop up is opened
        return true; 
    }
}

and don't forget to press the menu button or icon on Emulator or device