I started to build the app in Kotlin and I want to know how to correctly initialize variables. For example in Java it was like:
private TextView mSomeTextView;
And then we call findViewById in some methods. But in Kotlin I can't just write something like that, I need to:
private val textView: TextView = findViewById(R.id.text)
I write it under onCreate as I used to. Question: is it right place for it? If no -- where and how should I do it?
You should use lateinit
:
private lateinit var textView: TextView
override fun onCreate(savedInstanceState: Bundle?) {
...
textView = findViewById(R.id.text)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With