A SimpleRecyclerView with databinding for andorid list
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'
}
<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
bind.listView.onAttachEnd = {
Log.d("GridFragment", "onAttachEnd")
bind.root.postDelayed({
bind.listView.loadMore(FoodFactory.getFoodSample(), isLoading = false)
}, 3000)
}