Kotlin Android basic fundamental codes

Kotlin is now an official language on Android. Everyone wants to start the android app in kotlin because of it’s Modern, Expressive, safe and less code. Here we are sharing some change need to know before start developing an android application in Kotlin. It’s a very easy Kotlin Android basic fundamental, but yes you have to do practice with us.

Kotlin Android basic fundamental codes

 

If your Android application in Java you can also convert its into Kotlin. Read the post and get know change Java to Kotlin

 

Top Kotlin Android basic fundamental

Here we are sharing a basic and most improatent change requied, when you are building a Android app in kotlin. Also we are comparing it with java langauge syntax of android.

 

1.  get the Text from EditText

In Kotlin calling .text on your, EditText is fine no need to do getText or toString 

Even don’t need findViewById, just this code fine

 

2.  onClickListener on frgament

 

3. onClickListener on Activity

It’s more easy in kotlin no need inner method.

 

4. Extend class in kotlin

That’s little different, must remember.

The Java equivalent would be:

 

5. Override method (in Kotlin its fun)

Easy syntax in kotlin, remember it.

This is the opposite of Java, where type comes before name:

In Kotlin you don’t need to finish your lines with semicolons, hence the absence of colons in the above snippet. You can add colons if you really want to, but your code will be cleaner and easier to read without them

 

6.  Say goodbye to findViewById

Yes you read right no need more findViewByID , no more confused about widget id.

Everyone has knew about Java code , so we are not adding java code snip.

 

Note : Android studio provide support to convert existing code or project convert into Kotlin.

Android Studio 3.0 provides tools to help you start using Kotlin. Convert entire Java files or convert code snippets on the fly when you paste Java code into a Kotlin file.

java convert to kotlin

Source : https://developer.android.com/kotlin/

For example of first Android kotlin project (app development) follow this tutorial – Build Your First Android App in Kotlin


2 thoughts on “Kotlin Android basic fundamental codes

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.