Activityにメニューを追加

1134 ワード





android:id="@+id/add_item"
android:title="add"
/>
android:id="@+id/removee_item"
android:title="remove"
/>



//
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Activity,
//R.menu.main,
//menu, , Menu
getMenuInflater().inflate(R.menu.main, menu);

return true;// ,false,
}

// ,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_item:
Toast.makeText(FirstActivity.this, "This is add menu", Toast.LENGTH_LONG).show();
break;

case R.id.removee_item:
Toast.makeText(FirstActivity.this, "This is remove menu", Toast.LENGTH_LONG).show();
default:
break;
}
return true;
}