What are the two parameters Menu and menu in method onCreateOptionsMenu(Menu menu) and how to use this method.
I have another question why this pa
The intent of implementing this method is to populate de menu passed with the itens you define in the R.menu.game_menu layout file.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.game_menu, menu);
return true;
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.game_menu, menu)
return true
}
After inflating the menu with the itens you might want to add some action when they are selected:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item:
// Action goes here
return true;
default:
return super.onOptionsItemSelected(item);
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_item -> {
// Action goes here
true
}
else -> super.onOptionsItemSelected(item)
}
}