goodbye findViewById! Hello Kotlin!

phash(41)
Published in
#kotlin
Words
113
Reading
1 min
Listen
Play
8y

kotlin_250x250.png Here comes Kotlin

Hey folks
ever written an android app? I am... and it is annoying to always initialize your UI elements before using them...
you design your layout, here is the XML:

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/SucheFuer"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

then you use it:

...
public void onCreate(View view){
    ..
   TextView textView = findViewById(R.id.textView);
   textView.setText("new Text");
...
}

and so on.. BOOOOOORING!
here we go with Kotlin - JBrains JVM Language, that is officially supported by Android right now!
not only can you write cleaner, shorter code, you can also use some convinience methods out of the box

Image having the same XML like above, but in Kotlin you just do this:

fun onCreate(view: View){
    textView.text = "new Text"
}

uh! I like! I really do!
Kotlin comes closer to my heart with every day - what do you think of it?

goodbye findViewById! Hello Kotlin! | Ecency