Reputation: 5
I have a "-". It is linked with a decrement method which just decreases the quantity by 1. And if quantity is already is 1 then it shows a Toast... But I can't get the toast and the quantity is going in -1 if I press the button at 1.
public void decrement(View view) {
if(quantity == 1){
Toast.makeText(this, "You can order a min of 1 Coffees", Toast.LENGTH_SHORT).show();
return;
}
quantity = quantity - 1;
displayQuantity(quantity);
}
If quantity is already is 1 then it shows a Toast... But I can't get the toast and the quantity is going in -1 if I press the button at 1.
Upvotes: 0
Views: 38
Reputation: 3394
public void decrement(View view) {
if(quantity > 1){
quantity = quantity - 1;
displayQuantity(quantity);
} else if(quantity == 1){
Toast.makeText(this, "You can order a min of 1 Coffees", Toast.LENGTH_SHORT).show();
return;
} else{
// do nothing
}
}
Upvotes: 2