• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

public boolean onOptionsItemSelected(MenuItem item) not getting on selecting item from Menu

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class AlarmSenderHome extends Activity {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.custommenu, menu);
return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
Toast.makeText(getApplicationContext(), "Preference Selected", Toast.LENGTH_SHORT);
switch(item.getItemId())
{
case R.id.preferences:

Toast.makeText(getApplicationContext(), "Preference Selected", Toast.LENGTH_SHORT);
return true;
default:
return super.onOptionsItemSelected(item);



}


}
}

I can see menu on Screen But while selecting Menu items onOptionsItemSelected not getting triggred

Can some Help, where i am lacking in
 
Ranch Hand
Posts: 44
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have similar code implemented with the following exceptions:

1. I have no "default:" case.
2. I end each case with a "break;"
3. Outside of the switch-case block I have "return true;"
4. I @Override my onOptionsItemSelected() and I do not implement the super.onOptionsItemSelected()
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic