I try to inflate the popupmenu with a custom layout, I do not want to load it from the resources "menu". I have the following code:
imageButtonMasOpciones.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(getContext(), imageButtonMasOpciones);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Toast.makeText(getContext(),"Item : " + menuItem.getTitle(),Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
});
In that code the popupMenu is created well, but when I replace this line of code:
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
for this:
popup.getMenuInflater().inflate(R.layout.popup, popup.getMenu());
the application closes