I have two projects:
-
In one I open in an activity a
reciclerview
that I charge withcardviews
, these cardviews have a button that opens a popupmenu, all perfect. -
In the other project I try to do the same but within a
fragment
and it gives me an error inpopupmenu.show()
= null object pointer.
The code is exactly the same so I deduce that with a fragment it works differently.
I charge it in an adapter, so the reference is in the holder. NOTE: the popup is not null, hence the Log (to check), shows me the menu reference.
I interpret that the fault is that he does not know where or how to do the show ().
HELP !!
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopupMenu(holder.overflow);
}
});
}
private void showPopupMenu(View view) {
// inflate menu
PopupMenu popup = new PopupMenu(mContext, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_album, popup.getMenu());
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
Log.i("POP",popup.toString());
popup.show();
}