A simple Android app built with Kotlin that increments a counter each time a button is clicked. The app uses a TextView
to display the counter value and updates it dynamically on button press.
- Click the button to increase the counter.
- Displays the updated counter value instantly.
- Simple and clean UI using ConstraintLayout.
- Kotlin
- Android Studio
- ConstraintLayout
ClickCounterApp/
βββ app/
β βββ src/
β β βββ main/
β β β βββ java/com/example/clickcounter/
β β β β βββ MainActivity.kt
β β β βββ res/
β β β β βββ layout/
β β β β β βββ main_activity.xml
β β β β βββ drawable/
β β β β β βββ bg.xml
βββ build.gradle
βββ AndroidManifest.xml
class MainActivity : ComponentActivity() {
var counter = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
val btn: Button = findViewById(R.id.btn)
val result_txt: TextView = findViewById(R.id.textView)
btn.setOnClickListener {
result_txt.setText("" + increaseCounter())
}
}
fun increaseCounter(): Int{
counter++
return counter
}
}
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="48sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
- Clone this repository:
git clone https://github.com/naomi-afrin/ClickCounterApp.git
- Open Android Studio and open the project.
- Connect a physical or virtual device.
- Click Run βΆ to build and run the app.
- Add animations for button clicks.
- Implement dark mode support.
- Store the counter value using SharedPreferences.
Contributions are welcome! Feel free to fork this repo, make improvements, and submit a pull request.
This project is licensed under the MIT License.
Made with β€οΈ by Naomi Afrin Jalil