Google officially announced Kotlin as a first class language for Android development at Google I/O 2017. From Android Studio 3.0, Kotl...

Hello World - Kotlin Hello World - Kotlin

Hello World - Kotlin

Hello World - Kotlin

Google officially announced Kotlin as a first class language for Android development at Google I/O 2017. From Android Studio 3.0, Kotlin is included as Support for Android Studio. In this post, we will start the development of Android Application with Kotlin.

To Getting Started, you have to download Android Studio 3.0 Canary 1 or Add the Kotlin plugin in your existing Android Studio.

Create Android Project with Kotlin

Create new project in Android studio check the Kotlin support and start as usual with Android Studio 3.0. 
Android Studio 3.0
But for Android Studio with version less than 3.0, we have install plugin form Plugins menu manually by Selecting File-->Settings-->Plugins-->Browse Repositories--> Search and Select Kotlin. Then Click Install

Now inside activity_main.xml create the following UI
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.androidmads.kotlinsample_helloworld.MainActivity">

    <TextView
        android:id="@+id/helloTxtView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
In Android Studio 3.0, by default you have Kotin Activity. For Android Studio with Version less than 3.0, can convert their Java activity into Kotlin Activity.
Install Kotlin Plugin
  1. Select Tools --> Kotlin --> Configure Kotlin --> Click Sync Now. 
  2. Open Quick Search or Click Ctrl + Shift + A for Windows Users. 
  3. Search and Select convert java to kotlin or simply Selct Ctrl + Shift + Alt + K for Windows Users. 
Now your MainActivity.kt looks like in the following.
package com.androidmads.kotlinsample_helloworld

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast

class MainActivity : AppCompatActivity() {

    // Declaration
    var helloTextView: TextView? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Initialization
        helloTextView = findViewById(R.id.helloTxtView) as TextView
        // Assigning data to TextView in runtime
        helloTextView!!.text = "Hello Kotlin!";

        // Click Listener in Kotlin
        helloTextView!!.setOnClickListener({
            Toast.makeText(applicationContext, "Hello TextView Clicked", Toast.LENGTH_LONG).show();
        })
    }
}
Kotlin is a new Programming Language for Android Development. I hope Java is not deprecated for Android Development. Please tell what do you think about this tutorial as well as the future of Java in Android development in Comment Section.

13 comments:

  1. When you seek utilizing these watchwords recorded arranged by significance: "CutePDF Writer download free," you discover the connection to the CutePDF official website and the connections to download the CutePDF Writer programming. https://edit-pdf-ios-android.pdffiller.com/

    ReplyDelete
  2. Well, essentially they're all the same: these Android apps make it easier for their customers to manage their accounts and learn the latest about the company and its offerings.appvn apk

    ReplyDelete
  3. This content is written very well. Your use of formatting when making your points makes your observations very clear and easy to understand. Thank you. Hack APP Data APK

    ReplyDelete
  4. Customary visits recorded here are the most effortless strategy to value your vitality, which is the reason why I am setting off to the site regular, scanning for new, intriguing data. Many, much obliged Fred

    ReplyDelete
  5. One of the best, Description about>>> Hack App Data APK

    ReplyDelete
  6. Perfect post admin wonderful content thanks for sharing here.
    Hack App Data Pro

    ReplyDelete
  7. You want to use the application omlet arcade mod apk is a very good game site for everyone completely free

    ReplyDelete
  8. I like Your Article about Catholic Priests and Former Abortionist Confront Congress on Meaning of “Abortion” | Fr. Frank Pavone's Blog Perfect just what I was searching for! . excel spreadsheet consultant

    ReplyDelete
  9. Undeniably believe that which you said. Your favorite reason seemed to be on the net the simplest thing to be aware of. I say to you,Download 2023 Excel Calendar Template

    ReplyDelete

Please Comment about the Posts and Blog