我想应该检查一下你的id是不是和layout里的一样
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" > <item
android:id="@+id/action_luncha"
android:orderInCategory="100"
android:title="@string/action_luncha"
app:showAsAction="always"/></menu>
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_luncha) {
lunchActivityA();
return true;
} else (...) {
......
}
return super.onOptionsItemSelected(item);
}
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" > <item
android:id="@+id/action_luncha"
android:orderInCategory="100"
android:title="@string/action_luncha"
app:showAsAction="always"/></menu>
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_luncha) {
lunchActivityA();
return true;
} else (...) {
......
}
return super.onOptionsItemSelected(item);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货