Hi, I'm new to android programming (JAVA). I wanted your great help.
I have two buttons and a textview, one to increase and the other to subtract and I want to increase the number that is in the text through the buttons
this is my code
private static int valor =1;
TextView cantidad=view.findViewById(R.id.txtcantidad);
Button aumentar=view.findViewById(R.id.btnaumntar);
Button disminuir=view.findViewById(R.id.btndisminuir);
I don't know how to increase or decrease my textview through the buttons
thanks for your help
Just add a listener (
OnClickListener
) to the buttons, increase or decrease the value of the variable. It's important to convert the value you increase or decrease using to a StringString.valueOf(...)
, before adding it to theTextView
: