Posts

Showing posts from November, 2017

Using Kotlin JSON Parsing with Listview

In this post, we’ll learn how to parse JSON data using Moshi library.  What is Moshi? Moshi is an open source modern JSON library for both Android and Java, for parsing JSON. It is developed by Square (Jake and Jesse).It is like other JSON parsing libraries like Retrofit, GSON etc. Step 1 :- Adding Internet permissions to manifest.xml as Fallows in red:   <? xml version= "1.0" encoding= "utf-8" ?> < manifest xmlns: android = "http://schemas.android.com/apk/res/android" package= "com.example.ravi.jsonparseing" > < uses-permission android :name= "android.permission.INTERNET" /> < application android :allowBackup= "true" android :icon= "@mipmap/ic_launcher" android :label= "@string/app_name" android :roundIcon= "@mipmap/ic_launcher_round" android :supportsRtl= "true" android :theme= "@style

Kotlin RecyclerView Example

Source code of RecyclerView Adapter   Step 1 :- Create new kotlin class and named as KotlinRecyclerAdapter.kt and paste the following.    import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import android.support.v7.widget.RecyclerView /** * Created by ravi on 11/7/17. */ class KotlinRecyclerAdapter( private val moviesList : List<Data>) : RecyclerView.Adapter<KotlinRecyclerAdapter.MyViewHolder>() { inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { var title : TextView = view.findViewById <TextView> (R.id. title ) var year : TextView = view.findViewById <TextView> (R.id. year ) var genre : TextView = view.findViewById <TextView> (R.id. genre ) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { val itemView = LayoutInflater.from(parent. context ) .inflate(R.
Image
Configure Kotlin in Project  Now the IDE knows what to do with Kotlin, but your project app doesn’t, so your next move is to modify the project’s build configuration. Go to Tools\Kotlin\Configure Kotlin in Project . Select Android with Gradle from the Choose Configurator popup that appears.     On the Configure Kotlin in Project popup, select the plugin version you want to use (at the time of writing this tutorial, the current version is 1.0.3) and click OK .   This action will make a number of changes to your build.gradle files.

Kotlin SetUp with Android Studio

Image
This tutorial describing  how to create Android applications with Kotlin. It is based on the latest and greatest Android and Android Studio 3.0 release.   Let's Start Kotlin with Android Studio <3.0 To do so, start Android Studio and open Plugins from the Configure menu. Now, press the Install JetBrains plugin…​ button.  In the opened dialog, search for Kotlin, select the corresponding plugin and press Install.   After the installation is finished, restart Android Studio and you are ready to use Kotlin.