To add text to a TextView in Kotlin, you can use the `text` property of the TextView. Here's an example:
// Assuming you have a TextView with id "myTextView" in your layout XML file
val myTextView = findViewById<TextView>(R.id.myTextView)
// Set the text of the TextView
myTextView.text = "Hello, world!"
In this example, we first retrieve a reference to the TextView using its id (`R.id.myTextView`). Then, we set its text property to the string "Hello, world!" using the assignment operator (`=`).
You can replace the string "Hello, world!" with any other string you want to display in the TextView.
Comments
Post a Comment