is there a way to do this:
var num = 0
plusbtn.setOnClickListener {
num
textView2.text = num.toString()
}
minbtn.setOnClickListener {
num--
textView2.text = num.toString()
}
but instead of the textView2, I use a inputtype thing. So that I can still type the numbers in it, but also use the 2 buttons to increment en decrement.
CodePudding user response:
I have made this. This now works as I want it to:
var num: Int
plusbtn.setOnClickListener {
num = penaltytimetxt.text.toString().toInt()
if(num < 99){
num
penaltytimetxt.setText(num.toString())
}
else {
Toast.makeText(this, "Penalty time cannot go over 99", Toast.LENGTH_SHORT).show()
}
}
minbtn.setOnClickListener {
num = penaltytimetxt.text.toString().toInt()
if(num > 0){
num--
penaltytimetxt.setText(num.toString())
}
else {
Toast.makeText(this, "Penalty time cannot go under 0", Toast.LENGTH_SHORT).show()
}
}
CodePudding user response:
in TextInputEditText yo should use setText method
var num = 0
plusbtn.setOnClickListener {
num
textView2.setText(num.toString())
}
minbtn.setOnClickListener {
num--
textView2.setText(num.toString())
}