Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 键入时未调用TextInputText addTextChangedListener_Android_Kotlin_Material Design - Fatal编程技术网

Android 键入时未调用TextInputText addTextChangedListener

Android 键入时未调用TextInputText addTextChangedListener,android,kotlin,material-design,Android,Kotlin,Material Design,我有一个带有一个textinputtext(材质设计组件)的简单表单,无法侦听文本更改。使用addTextChangedListener添加TextWatcher似乎没有任何效果。当我运行我的应用程序并使用虚拟键盘输入时,不会调用任何回调(不会命中调试断点),并且我的TextView也不会更新: 活动: class MainActivity : AppCompatActivity() { private lateinit var webBankingIdLayout: TextInp

我有一个带有一个
textinputtext
(材质设计组件)的简单表单,无法侦听文本更改。使用
addTextChangedListener
添加
TextWatcher
似乎没有任何效果。当我运行我的应用程序并使用虚拟键盘输入时,不会调用任何回调(不会命中调试断点),并且我的
TextView
也不会更新:

活动:

class MainActivity : AppCompatActivity() {


    private lateinit var webBankingIdLayout: TextInputLayout
    private lateinit var webBankingIdInput: TextInputEditText
    private lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        webBankingIdLayout = findViewById<TextInputLayout>(R.id.web_banking_id_input_layout)
        webBankingIdInput = TextInputEditText(webBankingIdLayout.context)
        textView = findViewById<TextView>(R.id.temp_text)

        webBankingIdInput.addTextChangedListener(object: TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                s!!
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                s!!
                textView.text = s!!
            }
            override fun afterTextChanged(s: Editable?) {
                s!!
            }
        })
    }
}
为什么我的代码不起作用,如何在文本输入中收听字符输入?

我的目标是隐藏一个按钮,直到在字段中输入最少的字符数。

您需要替换:

webBankingIdInput = TextInputEditText(webBankingIdLayout.context)
致:

webBankingIdInput=findViewById(R.id.web\u banking\u id\u text\u输入)

我也遇到了类似的问题,原因是没有在XML中设置android:inputType参数。

有道理。我猜我假设将上下文传递给构造函数将返回布局中定义的实例。我猜我错了!
webBankingIdInput.text = "Yippee!"
webBankingIdInput = TextInputEditText(webBankingIdLayout.context)
webBankingIdInput = findViewById<TextInputEditText>(R.id.web_banking_id_text_input)