Issue
I'm newbie.
I want to change text of
TextView
While click on it.
My code:
val text: TextView = findViewById(R.id.android_text) as TextView
text.setOnClickListener {
text.setText(getString(R.string.name))
}
Output: I got the output but showing use property access syntax.
Can anyone tell me how to do it?
Thanks in advance.
Solution
In kotlin don't use getters and setters as like in java.The correct format of the kotlin is given below.
val textView: TextView = findViewById(R.id.android_text) as TextView
textView.setOnClickListener {
textView.text = getString(R.string.name)
}
To get the values from the Textview
we have to use this method
val str: String = textView.text.toString()
println("the value is $str")
Answered By - Nithinlal
Answer Checked By - Clifford M. (JavaFixing Volunteer)