Android Programming Tutorials

(Romina) #1
What's Your Preference?

/>

</menu>

We reference an ic_menu_preferences.png file, which you can obtain from


the same directory where you got ic_menu_add.png.


Of course, if we modify the menu XML, we also need to modify the


LunchList implementation of onOptionsItemSelected() to match, so replace


the current implementation with the following:


@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.add) {
startActivity(new Intent(LunchList.this, DetailForm.class));

return(true);
}
else if (item.getItemId()==R.id.prefs) {
startActivity(new Intent(this, EditPreferences.class));

return(true);
}

return(super.onOptionsItemSelected(item));
}

All we are doing is starting up our EditPreferences activity.


If you recompile and reinstall the application, you will see our new menu


option:


138
Free download pdf