I want to show PopupMenu it is inside recycerview but
When i click menuButton app crashing and to finding the issue i removed showPopupMenuMenu() method calling from setOnClickListener and replaced with toast it is working fine
The problem is in showPopupMenuMenu() method any one please help me to solve this issue
holder.menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
showPopupMenuMenu(holder,position);
}catch (Exception e){
Log.e("showPopupMenuMenu",e.getMessage()+"");
}
}
});
private void showPopupMenuMenu(MyViewHolder holder, final int position){
//creating a popup menu
PopupMenu popup = new PopupMenu(context, holder.menuButton);
//inflating menu from xml resource
popup.inflate(R.menu.recyclerview_option_menu);
//adding click listener
try{
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.edit_menu:
//handle menu1 click
if (context instanceof MyAddressActivity) {
((MyAddressActivity) context).openEditAddressActivity(position, true);
} else if (context instanceof CheckoutLocationActivity) {
((CheckoutLocationActivity) context).openEditAddressActivity();
}
break;
case R.id.delete_menu:
//handle menu2 click
if (context instanceof MyAddressActivity) {
((MyAddressActivity) context).deleteAddressItem(position);
} else if (context instanceof CheckoutLocationActivity) {
((CheckoutLocationActivity) context).mCheckoutLocationActivityPresenter.deleteAddressItem(position);
}
break;
}
return false;
}
});
}catch (Exception e){
Log.e("showPopupMenuMenu","setOnMenuItemClickListener "+e.getMessage()+"");
}
//displaying the popup
popup.show();
}
Binary XML file line #32: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f0300cc a=-1}
R.menu.recyclerview_option_menu
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/edit_menu"
android:title="@string/edit" />
<item
android:id="@+id/delete_menu"
android:title="@string/delete" />
</menu>
Try this please;
openPopUpMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(activity, v);
popupMenu.getMenuInflater().inflate(R.menu.pop_up_menu, popupMenu.getMenu());
popupMenu.show();
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getTitle().equals("1. item title")) {
//do something
} else if (menuItem.getTitle().equals("2.item Title")) {
// do something
}
return false;
}
});
}
});