Android menu creation and implementation
To create a menu resource, create an yourmenu.xml file inside your project's
yourmenu.xml
If menu item selected..
res/menu/
directoryyourmenu.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_next" android:icon="@drawable/icon_next" android:title="Next" /> <item android:id="@+id/menu_back" android:icon="@drawable/icon_back" android:title="Back" /> </menu>
Creation
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.yourmenu, menu); return true; }
If menu item selected..
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_next: //your code here.. return true; default: return super.onOptionsItemSelected(item); } }
Comments
Post a Comment