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" >
  2. <item
  3. android:id="@+id/action_settings"
  4. android:orderInCategory="100"
  5. android:showAsAction="never"
  6. android:title="@string/menuSettings"/>
  7. <item
  8. android:id="@+id/menuReport"
  9. android:orderInCategory="100"
  10. android:showAsAction="never"
  11. android:title="@string/menuReport"/>
  12. </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.