creating an options menu with quit application function
- by Domen Tomažin
Hello, I'm writing an application for android and I would like to insert an options menu, that would have only one function and that is to quit an application.
My options_menu.xml looks like this (I created a new folder under res called menu - just like the instructions said):
Than I added the following code to my java class file:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.quit:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
I also defined the @string/quit in values - strings.xml file, but it still says that there is an error:
C:\Users\Domen\workspace\Lovne Dobe1.1\res\menu\options_menu.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/quit')
So if anybody can help I would be very grateful.