Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Android and the fly likes public boolean onOptionsItemSelected(MenuItem item) not getting on selecting item from Menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "public boolean onOptionsItemSelected(MenuItem item) not getting on selecting item from Menu" Watch "public boolean onOptionsItemSelected(MenuItem item) not getting on selecting item from Menu" New topic
Author

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

Hussain Jamali
Greenhorn

Joined: May 10, 2011
Posts: 1
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
Bill Mote
Ranch Hand

Joined: Feb 04, 2010
Posts: 44
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()
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: public boolean onOptionsItemSelected(MenuItem item) not getting on selecting item from Menu
 
Similar Threads
Menu problem
Gertting Menu from MenuItem
FTP downloading issues
android gridview with fling + flipper
Problems with listview and checkbox event