Question

I want to know about menu.I tried using some codes given in net.It seems simple but can't get output when i run application.I used onCreateOptionMenu and menuinflater.I created a new folder under res and named it as menu and i add item in menu.xml under it.But can't get output.kindly let me know my mistake.

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/icon"
     android:title="ICON"/>
<item android:id="@+id/text"
    android:title="Text" />
<item android:id="@+id/icontext"
    android:title="Icon and text"
     />
</menu>

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;

public class Simple extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;                  
 }
 }
Was it helpful?

Solution

Have to click the predefined menu button in emulator to make our menu option visible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top