xml file
=====
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menuitem1"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Title1"/>
<item
android:id="@+id/menuitem2"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Title2"/>
</menu>
=====
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menuitem1"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Title1"/>
<item
android:id="@+id/menuitem2"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Title2"/>
</menu>
java file
=====
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action_bar_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuitem1:
Toast.makeText(getApplicationContext(), "Item1 clicked"+item.getTitle(), Toast.LENGTH_SHORT).show();
break;
case R.id.menuitem2:
Toast.makeText(getApplicationContext(), "Item2 clicked"+item.getTitle(), Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
No comments:
Post a Comment