Pop up menu simply show Menu in a pop up window anchored to a View.
It displays the pop up below the anchor view if it finds space otherwise above the anchor view.
If we touch outside of it, then it will dismiss the pop up menu.
First, we need to define menu xml file in menu folder.
add_info_pop_up_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/add_info" android:title="Add Info" />
<item android:id="@+id/delete" android:title="Delete"/>
</menu>
Then create Pop up in java
PopupMenu popup = new PopupMenu(getActivity(), mMoreInfo);
// mMoreInfo is a button, and I am doing all this on click of mMoreInfo
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.add_info_pop_up_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
if (item.getTitle().equals("Add Info")) {
Toast.makeText(getActivity(), "Add Info.", Toast.LENGTH_LONG).show();
}
if (item.getTitle().equals("Delete")) {
//ParseObject cln = ParseObject.createWithoutData("User_Pitch", videoDetailsArrayList.get(position).getObjectId());
Toast.makeText(getActivity(), "Delete.", Toast.LENGTH_LONG).show();
}
return true;
}
});
popup.show();//showing popup menu
0 Comment(s)