- textView is object variable which was Created from TextView class , later it was connected to id of TextView from xml ,named text_view_id on activity class.
.text method work as getText() / setText() method from java - if
.text method is left side of = operator than it will work as setText() - and if
.text is on right side that it will work as getText() but it return Editable! format , so we need to convert it to string with .toString() method
textView.text = “$message” is used to set message in String format to display
package myfirstkotlinapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
class MainActivity : AppCompatActivity() {
// Declare variable of TextView Type
lateinit var textView : TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//accessing our textview from layout
textView = findViewById(R.id.text_view_id)
// assign string to text view
textView.text = "Enter your Number : "
// get string from textView
val msg : String = textView.text.toString()
}