Kotlin is an official language to make Android Application since Google I/O 2017. Kotlin is a fun, expressive and modern language which can be considered as the language of the future to create Android Applications compared to Java. In this tutorial, you are going to create your first Android Application with Kotlin : a simple counter with plus and minus buttons.

You can also discover this tutorial on the SSaurel’s Channel on YouTube :

First step is to create a new Android project with Android Studio with the Kotlin support enabled.

 

Creating the User Interface

The User Interface of our Counter made with Kotlin will be quite simple with three components :

  • A Plus Button to increment the Counter
  • A Minus Button to decrement the Counter
  • A TextView to display the value of the Counter

It will give us the following code for the layout of the Main Activity :

 

Writing the Kotlin Code of the Main Activity

Now, it’s time to write the Kotlin Code of the Main Activity. Thanks to the Kotlin Android Extensions plugin, we won’t need to make findViewById() calls to get the references of the Views in our MainActivity.

Then, we define a property to store the value of our Counter and we set OnClickListener on the plus and the minus buttons to update the Counter value when the user will click on the buttons. This gives us the following code :

 

Testing our Counter App made with Kotlin

Now, it’s time to test our Counter App made with Kotlin. You should have the following result on your device :

This tutorial learning you how to create your first Android App with Kotlin is ended. In the future, we will continue by creating more complex Applications. Don’t hesitate to give me your ideas in comments.

To discover more tutorials on Android Development, you can also visit the SSaurel’s Channel on YouTube :