Menu

In Donation, introduce the following menu event handler:

1. @Override
2. public boolean onOptionsItemSelected(MenuItem item)
3. {
4. switch (item.getItemId())
5. {
6. case R.id.action_settings: Toast toast = Toast.makeText(this, "Settings Selected", Toast.LENGTH_SHORT);
7. toast.show();
8. break;
9. }
10. return true;
11. }

We already have a menu called ‘donate.xml’ in the res folder. Add a new menu item like the one shown below:

1. <menu xmlns:android="http://schemas.android.com/apk/res/android" >

3. <item
4. android:id="@+id/action_settings"
5. android:orderInCategory="100"
6. android:showAsAction="never"
7. android:title="@string/menuSettings"/>

9. <item
10. android:id="@+id/menuReport"
11. android:orderInCategory="100"
12. android:showAsAction="never"
13. android:title="@string/menuReport"/>

15. </menu>

This will require a new String in the strings.xml file:

1. <string name="menuReport">Report</string>

Run the app and when you press the menu hardware button and select ‘settings’, you should see the toast message appear.