/SolarListView

Using Recyclerview with Data Binding and ViewModel

Primary LanguageKotlinApache License 2.0Apache-2.0

SimpleRecyclerView


A SimpleRecyclerView with databinding for andorid list

License

Dependency Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

And add a dependency code to your module's build.gradle file.

buildFeatures {
  dataBinding true
}
dependencies {
  implementation 'com.github.KennethSS:SimpleRecyclerView:1.0.2'
}

Usage

Basic Example

Prepare to making item

<layout>    
    <data>
        <!-- If you wan't to use that you have not to declare -->
        <variable
            name="vm"
            type="com.solar.recyclerviewsample.viewmodel.FoodViewModel" />
    </data>
  
    <com.solar.recyclerview.SolarRecyclerView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        bind:loading="@{true}"
        bind:vm="@{vm}"
        bind:items="@{vm.foodGridList}"
        bind:decoration="@{6}"
        tools:listitem="@layout/item_food_grid">
    </com.solar.recyclerview.SolarRecyclerView>
</layout>
data class Food (
    val title: String,
    val subtitle: String,
    val img: Int,
    override val layoutRes: Int = R.layout.item_food_menu
) : ItemType

Set Paging

bind.listView.onAttachEnd = {
  Log.d("GridFragment", "onAttachEnd")
  bind.root.postDelayed({
    bind.listView.loadMore(FoodFactory.getFoodSample(), isLoading = false)
  }, 3000)
}