menu folder >> options_cart_item.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_edit"
android:title="Edit"/>
<item
android:id="@+id/menu_Remove"
android:title="Remove"/>
</menu>
Add Button or any object Click Listener
holder.cOptions.setOnClickListener(v -> {
PopupMenu popupMenu = new PopupMenu(mContext, holder.cOptions);
popupMenu.inflate(R.menu.options_cart_item);
popupMenu.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()){
case R.id.menu_edit:
Intent intent = new Intent(mContext, ProductActivity.class);
intent.putExtra("productId", model.getProductId());
intent.putExtra("qua", model.getQuantity());
mContext.startActivity(intent);
//Toast.makeText(mContext, "Edit", Toast.LENGTH_SHORT).show();
break;
case R.id.menu_Remove:
String x = FirebaseAuth.getInstance().getUid();
FirebaseDatabase.getInstance().getReference().child("Hospital").child("Users").child(x)
.child("Cart").child(model.getProductId()).removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
notifyItemRemoved(position);
//Toast.makeText(mContext, "Remove", Toast.LENGTH_SHORT).show();
}
});
break;
}
return false;
});
popupMenu.show();
});
0 Comments