java - Menu xml in MainActivity? -
i'm going crazy! have source why goes error?
this menu.xml mainactivity
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <group android:id="@+id/group1"> <item android:id="@+id/item1" android:title="x"></item> <item android:id="@+id/item2" android:title="y"></item> <item android:id="@+id/item3" android:title="z"></item> <item android:id="@+id/item4" android:title="share"></item> </group> </menu>
and java file
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu_main, menu); return true; } public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.item1: code } return true; case r.id.item2: code return true; case r.id.item3: code return true; case r.id.item4: intent intent = new intent(intent.action_send); intent.settype("text/plain"); intent.putextra(intent.extra_text, "hxxx"); intent.putextra(android.content.intent.extra_subject, "check out site!"); startactivity(intent.createchooser(intent, "share")); return true; default: return super.onoptionsitemselected(item); } } }
why give me error in line: case r.id.item4: error multiple markers @ line - item4 cannot resolved or not field - item4 cannot resolved or not field
i'm guessing menu.xml file saved in 'res/menu/menu.xml'. if so, try:
public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu, menu); return true; }
otherwise may in different folder, if menu.xml file in layout folder (ie 'res/layout/menu.xml', try:
public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. menuinflater inflater = getmenuinflater(); inflater.inflate(r.layout.menu, menu); return true; }
Comments
Post a Comment