• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps android option menu

vag

Newbie
I am new in android and trying to create option menu, but when I press menu button menu doesn't appear.

I Create menu.xml in res/menu. the code is here

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/settings_label"
android:alphabeticShortcut="@string/settings_shortcut" />
</menu>

then in main activity I override onCreateOptionMenu and onOptionItemSelected function, here are codes

public boolean onCreateOptionMenu(Menu menu)
{
//super.onCreateOptionsMenu(menu);
MenuInflater inflate=getMenuInflater();
inflate.inflate(R.menu.menu,menu);
return true;
}
public boolean onOptionItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.settings:
Intent n = new Intent(SudokuActivity.this,About.class);
startActivity👎;
return true;
}
return false;
}

can someone explain what is wrong?

P.S sorry for bad english))
 
I am new in android and trying to create option menu, but when I press menu button menu doesn't appear.

I Create menu.xml in res/menu. the code is here

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/settings_label"
android:alphabeticShortcut="@string/settings_shortcut" />
</menu>

then in main activity I override onCreateOptionMenu and onOptionItemSelected function, here are codes

public boolean onCreateOptionMenu(Menu menu)
{
//super.onCreateOptionsMenu(menu);
MenuInflater inflate=getMenuInflater();
inflate.inflate(R.menu.menu,menu);
return true;
}
public boolean onOptionItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.settings:
Intent n = new Intent(SudokuActivity.this,About.class);
startActivity👎;
return true;
}
return false;
}

can someone explain what is wrong?

P.S sorry for bad english))

You probably didn't put your activity in android manifest xml file. Write this under manifest.

<activity android:name=".About"
android:label="@string/about_title">

</activity>

And you better write the error that written in LogCat.
 
Not sure if this is the problem, but you're missing the letter S in

onCreateOptionsMenu

you have

onCreateOptionMenu
 
  • Like
Reactions: vag
Back
Top Bottom