Ask Your Question

Revision history [back]

Here's an example of how to use Kotlin to change the text displayed in a TextView on an Android device:

  1. First, find the TextView that you want to change the text of. You can do this using findViewById() or view binding.

For example:

val myTextView = findViewById<TextView>(R.id.my_textview)
  1. Call the setText() method on the TextView, passing in the new text you want to display.

For example:

myTextView.setText("Hello, world!")

Alternatively, you can use the shorthand syntax:

myTextView.text = "Hello, world!"

That's it! Now the text displayed in the TextView will be updated with the new text you provided.