I am currently making a small application and this is what I want to do:
every time I click on the "+" button, I want to increment my counter which I have successfully done. Every time I click the "-" button, I want to decrement my counter which again, I have successfully done. however, when the value of the counter reaches 0, I want my button for "-" to be no longer clickable and be greyed out, how would i be able to do this?
Asked
Active
Viewed 6,660 times
-6

carl saptarshi
- 345
- 1
- 5
- 17
-
If you have successfully completed increment and decrement logic then you can disable your button easily. – Pankaj Jul 08 '15 at 08:42
4 Answers
2
what you can do is in your onCreate Method
Button fewer=(Button)findViewById(R.id.fewer);
and then you can use .setClickable(false);

Moubeen Farooq Khan
- 2,875
- 1
- 11
- 26
0
use this
button.setClickable(false);

Fixus
- 4,631
- 10
- 38
- 67
-
when i put that into the java code, it says that "cannot resolve symbol button", what should button relate to? – carl saptarshi Jul 08 '15 at 07:59
-
-
@carlsaptarshi this is just example. 'button' is an instance of class Button. So in your code you need to replace it with your variable name – Fixus Jul 08 '15 at 08:04
-
my button id is : android:id = "@id/fewer" so do i call my button fewer.setClickable(false)? – carl saptarshi Jul 08 '15 at 08:04
-
1replace 'button' with variable that is used in your activity. You have some actions made on the buttons so in your code you need to have instance of the button. Use it – Fixus Jul 08 '15 at 08:06
0
You could disable the button with setClickable(false)
(as metnionned by Fixus) or you could also check in the listener if the value is equal to 0, and then if it's the case, just do nothing

Bxtr
- 316
- 1
- 13