Creation of Options Menu not Working

Put your problem here if it does not fit any of the other categories.

Creation of Options Menu not Working

Postby killa.fr0gg » Wed Apr 22, 2009 2:02 am

Hi all,

I'm trying to add an Options Menu to my activity, but apparently I'm doing something wrong, though for the life of me I can't figure out why. I've compared my code to everything I can find on the internet, and as far as I can tell it's word-for-word perfect. Will someone tell me what I'm doing wrong? Thank you so much in advance!

public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, ADD_ADJECTIVE, 0, "Add Adejective");
menu.add(0, ADD_OBJECT, 0, "Add Object");
return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ADD_ADJECTIVE:
alert1.show();
return true;
case ADD_OBJECT:
alert2.show();
return true;
}
return false;
}

I should probably mention that the specific errors returned are that ADD_ADJECTIVE and ADD_OBJECT cannot be resolved. Again thanks.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Top

Postby tanran » Wed Apr 22, 2009 2:42 am

i havn't met this prolem, you can set breakpoint at onOptionsSelectedItem method.
tanran
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Apr 22, 2009 2:16 am

Postby tanran » Wed Apr 22, 2009 3:01 am

i havn't met this prolem, you can set breakpoint at onOptionsSelectedItem method.
tanran
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Apr 22, 2009 2:16 am

Postby padde » Wed Apr 22, 2009 11:00 am

Are ADD_ADJECTIVE and ADD_OBJECT defined as int in that class?
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby killa.fr0gg » Wed Apr 22, 2009 6:52 pm

I actually figured it out in the wee hours of the morning. turns out all I had to do was change the identifiers to numbers. Bah! I hate stupid careless mistakes. Thanks to padde, had I not figured it out, your comment would have done it for me.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Postby alpesh_harsoda » Wed Apr 29, 2009 1:12 pm

yoy gave the same order id for both menu item.use the different id for both.
Regards,
Alpesh Patel,
Logistic Infotech
http://www.logisticinfotech.com
User avatar
alpesh_harsoda
Senior Developer
Senior Developer
 
Posts: 106
Joined: Sat Sep 20, 2008 12:35 pm
Location: Rajkot,Gujarat(India)

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 27 guests