Preview

Preview Image Preview Image

  • Q: What are we trying to achieve here?

  • A: We're trying to store & show list of Names.

AndroidManifest.xml

Let's add permissions first.

<uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

build.gradle (Module: app)

  1. And time to add dependencies.

apply plugin: 'kotlin-kapt'
dependencies {
    ...
    // UI Component
    implementation 'androidx.recyclerview:recyclerview:1.1.0'

    // Material design
    implementation "com.google.android.material:material:1.1.0"

    // LifeStyle Components
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    kapt "androidx.lifecycle:lifecycle-compiler:2.2.0"

    // Kotlin Components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4"

    // Room Components
    implementation "androidx.room:room-runtime:2.2.5"
    kapt "androidx.room:room-compiler:2.2.5"
    implementation "androidx.room:room-ktx:2.2.5"
    ...
}

ListItem.kt

List item data class

MainListAdapter.kt

Create Adapter for RecyclerView List - which will display list of words.

list_main.xml

  • Layout file for single row - which is used in above adapter.

  • ImageView we'll be using in next article.

NameTable.kt

Create table. For this article, we're creating name table.

NameDAO.kt

Data Access Object - An interface - with which we'll be able to access Name table.

NameRepository.kt

Repository with which we'll be able to insert / delete / update / read.

NameRootDatabase.kt

Database connection

NameViewModel.kt

ViewModel for async, easy, quick access to Name table.

activity_main.xml

Layout for MainActivity

activity_additem.xml

Layout for AddItemActivity

MainActivity.kt

AddItemActivity.kt

Last updated

Was this helpful?