Skip to content

Instantly share code, notes, and snippets.

@amirul12
Created May 25, 2019 05:55
Show Gist options
  • Select an option

  • Save amirul12/cea24c65670d41a4fc2691c8b8890008 to your computer and use it in GitHub Desktop.

Select an option

Save amirul12/cea24c65670d41a4fc2691c8b8890008 to your computer and use it in GitHub Desktop.
private void showOptionMenu(View view) {
PopupMenu popupMenu = new PopupMenu(mContext, view);
MenuInflater menuInflater = popupMenu.getMenuInflater();
menuInflater.inflate(R.menu.pizza_menu,popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PizzaMenuItemClickListener());
popupMenu.show();
}
private class PizzaMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {
/**
* Display Toast message on click of the options in the menu
*
* @param item
* @return
*/
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_favourite:
Toast.makeText(mContext, "Add to favourite", Toast.LENGTH_SHORT).show();
return true;
case R.id.order_now:
Toast.makeText(mContext, "Order Now", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment