gpt4 book ai didi

android - kotlin.NotImplementedError: EditText 上的 addTextChangedListenerher 未实现操作

转载 作者:太空狗 更新时间:2023-10-29 14:35:20 25 4
gpt4 key购买 nike

当我在我的 EditText 上调用 addTextChangedListener(textWacther) 并尝试运行该应用程序时,它只是在该字段中输入内容时关闭。我启用按钮返回的方式不正确吗?

class MainActivity : AppCompatActivity() {
lateinit var num1TextE: EditText
lateinit var resultText: TextView
lateinit var plusBtn: Button

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

num1TextE = findViewById(R.id.firstNum_TextE)
plusBtn = findViewById(R.id.plus_btn)
resultText = findViewById(R.id.result_TextV)
resultText.visibility = View.GONE

plusBtn.isClickable= false
plusBtn.isEnabled = false
num1TextE.addTextChangedListener(textWatcher)

plusBtn.setOnClickListener {
var num1 = num1TextE.text.toString().toInt()
var num2 = num2TextE.text.toString().toInt()
resultText.visibility = View.VISIBLE
resultText.text = "Result is ${num1 + num2}"
}
}

var textWatcher = object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {

}

override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
var test: String = num1TextE.text.toString()
if(! test.isEmpty()) {
plusBtn.isClickable = true
plusBtn.isEnabled = true
}
}
}
}

日志:

2019-07-31 17:02:01.633 3078-3078/com.example.mycalculator E/InputEventSender: Exception dispatching finished signal.
2019-07-31 17:02:01.633 3078-3078/com.example.mycalculator E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
2019-07-31 17:02:01.637 3078-3078/com.example.mycalculator E/MessageQueue-JNI: kotlin.NotImplementedError: An operation is not implemented: not implemented
at com.example.mycalculator.MainActivity$textWatcher$1.beforeTextChanged(MainActivity.kt:101)

最佳答案

如果您不打算使用回调,请删除 TODO("not implemented"),将 beforeTextChanged() { } 留空。

关于android - kotlin.NotImplementedError: EditText 上的 addTextChangedListenerher 未实现操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57292932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com