Created
November 3, 2019 09:32
-
-
Save longv/9ba600e8cdf6cdf72e2d5ec93ddfb009 to your computer and use it in GitHub Desktop.
Binding attributes for data binding RecyclerView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.longv.pokedex.databinding | |
import androidx.databinding.BindingAdapter | |
import androidx.recyclerview.widget.RecyclerView | |
@BindingAdapter(value = ["model"]) | |
fun setupRecyclerView(view: RecyclerView, model: RecyclerViewModel?) { | |
model?.apply { | |
view.adapter = DataBindingAdapter(bindingEntries) | |
view.layoutManager = layoutManager | |
itemDecoration?.apply { | |
view.addItemDecoration(this) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.longv.pokedex.databinding | |
import androidx.recyclerview.widget.RecyclerView | |
data class RecyclerViewModel(val layoutManager: RecyclerView.LayoutManager, | |
val itemDecoration: RecyclerView.ItemDecoration? = null, | |
val bindingEntries: List<DataBindingEntry> = emptyList()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment