You need to override your Activity's onOptionsItemSelected(...)
method.
Do it like this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) { // or whatever your id is, see the .xml file
// do something
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
Check the id of the options item (e.g. settings) and do specific stuff inside the if.
In order to add more items or manipulate the Id, take a look at your projects "menu" folder and the .xml file inside it.
Here the .xml file of my main menu:
And how it looks inside:
(you can manipulate this file and add more actions to it that will show up in the menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_one" android:title="Action 1"></item>
<item android:id="@+id/action_two" android:title="Action 2"></item>
<item android:id="@+id/action_three" android:title="Action 3"></item>
</menu>
In this case my menu would have 3 Actions, and you should check for them inside your onOptionsItemSelected(...)
method like that:
if (item.getItemId() == R.id.action_one) //...
... or use switch-case. For a more detailed explanation, you can also have a look at this tutorial:
http://mobile.tutsplus.com/tutorials/android/android-sdk-implement-an-options-menu/