Langsung ke konten utama

Postingan

Menampilkan postingan dengan label Kotlin

RecyclerView & ListView in Kotlin

In this tutorial, we will learn how to build ListView and RecyclerView with Custom Adapter in Kotlin. Everybody knows what is Listview and Recyclerview. So, without any introduction about them we will jump into the coding part of the Tutorial. Coding Part Kotlin ListView Example We should follow the same steps to create Activity with associated layout file for example MainActivity.kt with activity_main.xml Create ListView Adapter Create new class and named as MoviesListViewAdapter and paste the following. class MoviesListViewAdapter(private val activity: Activity, moviesList: List ) : BaseAdapter() { private var moviesList = ArrayList () init { this.moviesList = moviesList as ArrayList } override fun getCount(): Int { return moviesList.size } override fun getItem(i: Int): Any { return i } override fun getItemId(i: Int): Long { return i.toLong() } @SuppressLint("InflateParams", "ViewHolder") ...

Kotlin Android Extensions

Kotlin Android Extensions is an important Kotlin plugin that is similar to Butterknife. It will allow to recover views in android. Implementation Add the following plugins in your app level build.gradle file apply plugin:'com.android.application' apply plugin:'kotlin-android' apply plugin:'kotlin-android-extensions' Coding Part Create a new layout file in res folder, name it as activity_main.xml and paste the following codes <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:gravity="center" android:orientation="vertical" tools:context="com.androidmads.kotlinsample_helloworld.MainActivity"...

Kotlin - Basics

Hello Guys, we already knew that Google announced Kotlin is a new first class language for Android Development. So, we started the Kotlin series for learning Kotlin for android. We have seen the "Hello World" Program for Android in our previous post.  You can download Intellij idea Commuinty Edition or use Kotlin Online Compiler provided by Intellij In this post, we will learn the basics of kotlin. 1. Hello World The Following Snippet shows the Hello world Program and is similar to Java. fun main(args: Array <string>) { println("Hello, world!") } 2. Variables and Constants The Following Snippet shows the How to use Variables and Constants with Datatype in Kotlin. Variables can be re-assigned  // Variable - Values Can be reassigned var a = 10 a = a + 10 println(a) Constants cannot be re-assigned and if we did will error as "val cannot be reassigned" // Constants - Values cannot reassigned val x = 10 println(x) We can specify the Data types for...

Hello World - Kotlin

Kotlin - Android Programming Language 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="htt...