我正在尝试为我的简单应用添加操作按钮。我发现并使用了本教程https://developer.android.com/training/basics/actionbar/adding-buttons.html
以下是我的源代码(MainActivity.java)的相关部分:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_new_route:
(...)
return true;
case R.id.action_current_orders:
(...)
return true;
default:
return super.onOptionsItemSelected(item);
}
}
这是menu / main.xml
<item
android:id="@+id/action_new_route"
android:icon="@drawable/ic_route"
android:showAsAction="always"
android:title="New route"/>
<item
android:id="@+id/action_current_orders"
android:icon="@drawable/ic_orders"
android:showAsAction="always"
android:title="Current orders"/>
问题在于这两行:
case R.id.action_new_route:
(...)
case R.id.action_current_orders:
这些是我收到的错误消息:
action_current_orders cannot be resolved or is not a field
action_new_route cannot be resolved or is not a field
你能帮我解决这个问题吗?
谢谢。