Issue
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.
Solution
I have made this. This now works as I want it to:
plusbtn.setOnClickListener {
if(isEmpty(penaltytimetxt.text)){
penaltytimetxt.setText("0")
}
num = penaltytimetxt.text.toString().toInt()
if(num < 99){
num++
penaltytimetxt.setText(num.toString())
}
else {
Toast.makeText(this, "Penalty time cannot go over 99 sec", Toast.LENGTH_SHORT).show()
}
}
minbtn.setOnClickListener {
if(isEmpty(penaltytimetxt.text)){
penaltytimetxt.setText("0")
}
num = penaltytimetxt.text.toString().toInt()
if(num > 0){
num--
penaltytimetxt.setText(num.toString())
}
else {
Toast.makeText(this, "Penalty time cannot go under 0 sec", Toast.LENGTH_SHORT).show()
}
}
Answered By - masterturner96
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.