新手刷《第一行代码》2.2.6中在活动中添加menu出现错误:需要class,interface或enum
刷《第一行代码》2.2.6中在活动中添加menu
FirstActivity中,重写onCreateOptionsMenu()和OnOptionsItemSelected()方法:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.add_item:
Toast.makeText(this, "You clicked Add", Toast.LENGTH_SHORT).show();
break;
case R.id.remove_item:
Toast.makeText(this, "You clicked Remove", Toast.LENGTH_SHORT).show();
break;
default:
}
return true;
}
出现错误:需要class,interface或enum
Naaru
9 years, 3 months ago