Avatar ·

How to set text in EditText in Kotlin? Problem with setText()

Hello colleagues! I've just started learning Kotlin for Android and encountered a seemingly simple task — setting text in an EditText field programmatically. I'm writing a small notes app, and I need that when the "Load" button is pressed, pre-saved text is displayed in the EditText. Here's my code in Kotlin: ```kotlin val editText = findViewById(R.id.myEditText) editText.setText("Hello, world!") // Error! ``` But Android Studio underlines `setText()` in red and gives an error: "Unresolved reference: setText". I tried writing `editText.text = "Hello, world!"` — then the compiler complains about type mismatch: "Required: Editable, Found: String". I'm confused. I know that in Java everything worked through `editText.setText("text")`. Why doesn't this work in Kotlin?