DEV Community

loading...

Kotlin ListView example | Android

loizenai
Software Engineer - Founder at https://loizenai.com
・1 min read

Kotlin ListView example | Android

https://grokonez.com/android/kotlin-listview-example-android

In this Kotlin tutorial, we're gonna look at way to show list of items with Android ListView.

Related Post: Kotlin GridView example: Show List of Items on Grid | Android

More Practice: Kotlin SQLite example – CRUD operations with ListView | Android

I. Technologies

  • Android Studio 3
  • Kotlin 1.1.51

    II. Overview

    1. Goal

    We will build an Android App that uses ListView to show list of items:

kotlin-listview-goal

2. Android ListView

2.1 Input Types

Input (items) of a list can be arbitrary Kotlin object. We use an adapter to extract data from this Kotlin object, then assign object fields'value to the views in each row of ListView.

For example:


class Note {

    var id: Int? = null
    var title: String? = null
    var content: String? = null

    constructor(id: Int, title: String, content: String) {
        this.id = id
        this.title = title
        this.content = content
    }
}

Class for Kotlin object is called data model.

Kotlin ListView example | Android

https://grokonez.com/android/kotlin-listview-example-android

Discussion (0)