Challenge 3: Migrate to View Binding — Solution // app/build.gradle.kts android { // ...existing config... buildFeatures { viewBinding = true } } // MainActivity.kt (using the layout from Challenge 2 — a ConstraintLayout // with nameLabel, nameInput, and submitButton IDs) class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) binding.submitButton.setOnClickListener { val name = binding.nameInput.text.toString() binding.nameLabel.text = "Hello, $name!" } } } Notes: - After enabling viewBinding and rebuilding (Gradle sync), Android Studio generates ActivityMainBinding automatically from activity_main.xml — no manual class-writing needed, and no findViewById calls remain anywhere in MainActivity. - binding.root refers to the layout's root ConstraintLayout itself, passed to setContentView the same way R.layout.activity_main was passed directly in earlier chapters. - binding.nameInput and binding.submitButton are both correctly typed (EditText and Button respectively) purely from their XML tag and id — autocomplete surfaces exactly the members each type actually has, with no manual casting required. - If nameInput or submitButton were ever renamed or removed from the XML without updating MainActivity.kt, this code would fail to compile immediately, rather than crashing later at runtime the way a stale findViewById("wrong_id") call would.