Issue
This below code has Two values increment and decrement which are hooked to buttons in XML
int quantity = 0;;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trial_order);
}
public void increment(View view){
quantity = quantity + 1;
display(quantity);
}
public void decrement(View view){
quantity = quantity - 1;
display(quantity);
}
and increment works fine,decrement works fine too but when I press decrement it goes in 0,-1,-2,-3 and so on but I want 0 to be the final value when I use decrement button kindly help
Solution
Check after decreasing if the value of quantity is getting lower than 0 and set it accordingly:
Example:
public void decrement(View view){
quantity--;
if(quantity<0){
quantity=0;
}
display(quantity);
}
Answered By - ΦXocę 웃 Пepeúpa ツ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.