Search code examples
kotlintextviewandroid-edittext

Displaying the value of the EditText in the TextView at the Simultaneous(online) in kotlin


I want the text written inside the EditText to be displayed simultaneously in the TextView without pressing the button (kotlin)

thank you


Solution

  • Add a TextWatcher and in afterTextChanged update the TextView

    editText.addextChangedListener(object: TextWatcher {
        ...
        override fun afterTextChanged(s: Editable?) {
            s?.let { textView.text = it.toString() }
        }
    })
    

    Or if you're using the androidx.core:core-ktx library:

    editText.doAfterTextChanged { editable ->
        editable?.let { textView.text = it.toString()
    }