Skip to content

Instantly share code, notes, and snippets.

@ameliacv
Created March 25, 2018 13:30
Show Gist options
  • Save ameliacv/ec4b6956b8b3c1a669066609b3b37119 to your computer and use it in GitHub Desktop.
Save ameliacv/ec4b6956b8b3c1a669066609b3b37119 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_edit"
android:title="@string/label_edit"/>
</menu>
holder.mButtonMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popup = new PopupMenu(mContext, view);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.menu_pop_up, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_edit) {
// WHEN MENU CLIC
}
return true;
}
});
popup.show(); //showing popup menu
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment