在 Kotlin TextWatcher 中无按钮地乘以 2 个数字
Multiplying 2 numbers without buttons in Kotlin TextWatcher
我的目标是使用如下所示的 2 个 edittext 自动显示用户在下面的 textView 中输入的数字。我怎么能这样做?因为这是迷恋。如果您能详细解释一下,我将不胜感激。提前致谢。
items3=pronumber.text.toString() // Edittext
items4=proprice.text.toString()// Edittext
pronumber.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
TODO("Not yet implemented")
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text= "Toplam Tutar : "+(items3.toInt()*items4.toInt()).toString() +" TL" //TextView
}
} )
proprice.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
TODO("Not yet implemented")
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text= "Toplam Tutar : "+(items3.toInt()*items4.toInt()).toString() +" TL" //TextView
}
} )
items5=totalprice.text.toString()
您应该像这样更改您的代码
items3=pronumber.text.toString() // Edittext
items4=proprice.text.toString()// Edittext
pronumber.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
val first = pronumber.text.toString()
val second = proprice.text.toString()
totalprice.text = if (first.isBlank() || second.isBlank()){
"Toplam Tutar : 0 TL"
} else {
"Toplam Tutar : ${first.toInt().times(second.toInt())} TL"
}
}
} )
proprice.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text = if (first.isBlank() || second.isBlank()){
"Toplam Tutar : 0 TL"
} else {
"Toplam Tutar : ${first.toInt().times(second.toInt())} TL"
}
}
} )
items5=totalprice.text.toString()
我的目标是使用如下所示的 2 个 edittext 自动显示用户在下面的 textView 中输入的数字。我怎么能这样做?因为这是迷恋。如果您能详细解释一下,我将不胜感激。提前致谢。
items3=pronumber.text.toString() // Edittext
items4=proprice.text.toString()// Edittext
pronumber.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
TODO("Not yet implemented")
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text= "Toplam Tutar : "+(items3.toInt()*items4.toInt()).toString() +" TL" //TextView
}
} )
proprice.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
TODO("Not yet implemented")
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text= "Toplam Tutar : "+(items3.toInt()*items4.toInt()).toString() +" TL" //TextView
}
} )
items5=totalprice.text.toString()
您应该像这样更改您的代码
items3=pronumber.text.toString() // Edittext
items4=proprice.text.toString()// Edittext
pronumber.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
val first = pronumber.text.toString()
val second = proprice.text.toString()
totalprice.text = if (first.isBlank() || second.isBlank()){
"Toplam Tutar : 0 TL"
} else {
"Toplam Tutar : ${first.toInt().times(second.toInt())} TL"
}
}
} )
proprice.addTextChangedListener ( object:TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
totalprice.text = if (first.isBlank() || second.isBlank()){
"Toplam Tutar : 0 TL"
} else {
"Toplam Tutar : ${first.toInt().times(second.toInt())} TL"
}
}
} )
items5=totalprice.text.toString()