PopupMenu on Fragment Android

0

I have two projects:

  • In one I open in an activity a reciclerview that I charge with cardviews , 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 in popupmenu.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();
}
    
asked by Djya Web 28.07.2017 в 12:44
source

0 answers