I'm totally stuck why this is happening. The options menu was working just fine, but now it's no longer working.
When I hit the menu button, the menu opens, I tap it and nothing. It does register the MenuItem when I do my LogCat... I'm seriously going to pull my hair, I don't understand why this is happening.
06-06 22:19:07.899: DEBUG/MYTAG(23124): Stupid clicker id=save settings item id=2133000192 id2=2133065728
Below is the code and xml
@Override
public boolean onC开发者_高级运维reateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.settings, menu);
Log.d("MYTAG", "Clicked saved1");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Log.d("MYTAG", "Stupid clicker id="+item+" item id="+item.getItemId()+" id2="+R.mainmenuSettings.save1);
switch(item.getItemId()){
case R.mainmenuSettings.save1:
Log.d("MYTAG", "Stupid clicker");
break;
}
return super.onOptionsItemSelected(item);
}
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+mainmenuSettings/save1"
android:title="save settings"/>
</menu>
There's an error in your menu XML. The "id" attribute needs to start with "@+id/", so this needs to be "@+id/mainmenuSettingsSave1" or something similar. Also, you'll need to reference this in your code as R.id.mainmenuSettingsSave1:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/mainmenuSettingsSave1"
android:title="save settings"/>
</menu>
and
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.settings, menu);
Log.d("MYTAG", "Clicked saved1");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Log.d("MYTAG", "Stupid clicker id="+item+" item id="+item.getItemId()+" id2="+R.id.mainmenuSettingsSave1);
switch(item.getItemId()){
case R.id.mainmenuSettingsSave1:
Log.d("MYTAG", "Stupid clicker");
break;
}
return super.onOptionsItemSelected(item);
}
精彩评论