I just purchased this book and I have been following and reading a number of other resources on Android/Kitlin development.
The first thing that comes to me is that the book is very easy to read and follow, however, I am wondering right off the bat why the author is declaring lateInit variables for each of the different textviews and the button.
Seems like redundant code to me.
Why is this necessary
internal lateinit var gameScoreTextView: TextView internal lateinit var timeLeftTextView: TextView internal lateinit var tapMeButton: Button
and then doing
gameScoreTextView = findViewById<TextView>(R.id.game_score_text_view) timeLeftTextView = findViewById<TextView>(R.id.time_left_text_view) tapMeButton = findViewById<Button>(R.id.tap_me_button)
You can simply access your controls directly by the ID:
For example, in the book, you do this:
val newScore = "Your Score: " + Integer.toString(score) gameScoreTextView.text = newScore”
when instead, you could have used the id to do this
val newScore = "Your score: " + Integer.toString(score) game_score_text_view.text = newScore
similarly, with the onClickListener.
Instead of
tapMeButton.setOnClickListener{v -> incrementScore()}
you could have just used the ID
tap_me_button.setOnClickListener{v -> incrementScore()}
Seems like 6 lines of extra code.
Am I missing something?