package com.example.counterapp
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView
class MainActivity : AppCompatActivity() {
private var count = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val countText: TextView = findViewById(R.id.countText)
val incrementButton: Button = findViewById(R.id.incrementButton)
incrementButton.setOnClickListener {
count++
countText.text = "Count: $count"
}
}
}We added a click listener to the increment button. Each time the button is clicked, the count variable increases by 1. Then we update the TextView to show the new count using string interpolation. This keeps the UI in sync with the data.
For instrumented testing, this UI behavior can be tested on a real or virtual device to ensure the button click updates the text correctly.