Kotlin is now an official language on Android. It's expressive, concise, and powerful. Best of all, it's interoperable with our existing Android languages and runtime.
Basically, it is not very hard to write a code in Kotlin language but, we need to start from class day 1.
Lets say, for getting started in kotlin you can refer link, Get Started with Kotlin on Android
There are few syntax to be adopted and file format as .kt instead of .java.
In this tutorial, I will show how to create a listview with custom adapter in Kotlin Android Application,
Refer the below link for complete sample code:-
Download Sample Code
Have a look on few code snippets,
//MainActivity.kt
//CustomBaseAdapter.kt
//DetailActivity.kt
Basically, it is not very hard to write a code in Kotlin language but, we need to start from class day 1.
Lets say, for getting started in kotlin you can refer link, Get Started with Kotlin on Android
There are few syntax to be adopted and file format as .kt instead of .java.
In this tutorial, I will show how to create a listview with custom adapter in Kotlin Android Application,
Refer the below link for complete sample code:-
Download Sample Code
Have a look on few code snippets,
//MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package com.harshalbenake.koltinlist import android.content.Intent import android.graphics.Color import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.widget.EditText import android.widget.ListView import android.widget.Toast import kotlinx.android.synthetic.main.activity_main.* /** * Main Activity */ class MainActivity : AppCompatActivity() { //array variable initialized var listItems = arrayListOf |
//CustomBaseAdapter.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package com.harshalbenake.koltinlist import android.content.Context import android.graphics.Color import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.TextView /** * Custom Base Adapter */ class CustomBaseAdapter(list: ArrayList |
//DetailActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.harshalbenake.koltinlist import android.support.v7.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_detail.* /** * Detail Activity class */ class DetailActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail) //intent data extracted var strName= intent.getStringExtra("strNamePass") tv_detailname.text=strName } } |
No comments:
Post a Comment