Reputation: 1
Please..please help! I'm new with android development. After i create an app with simple menu. i click on the parent menu, i don't see the items in the submenu appeared. I don't know why is that. Enyone know this, please teach me.
i use nexus Emulator to show result. (nesux S (4.0", 480 X 800:ddpi)
create menu in the Menu folder -> menu-demo like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/addnew" android:title="add new">
<menu>
<item android:id="@+id/name" android:title="add name"></item>
<item android:id="@+id/age" android:title="Add age"></item>
</menu>
</item>
<item android:id="@+id/update" android:title="update"></item>
<item android:id="@+id/delete" android:title="delete"></item>
</menu>
i update Mainactivity.java in the src.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_demo, menu);
return true;
}
Upvotes: 0
Views: 327
Reputation: 42
You're missing android:showAsAction="[property"
.
You can use a few parameters for showAsAction
, such as always
, never
, and ifRoom
.
Add these properties to your code, so for example, a menu item that I always want to appear on the actionbar would be like
<item
android:id="@+id/test"
android:showAsAction="always"
android:title="test" >
</item
For submenus, you basically want the topmost selection shown as an action always
and the submenu shown never
.
Upvotes: 1