Created
August 22, 2018 15:46
-
-
Save SeongUgJung/798dd3b17578f00b5217cfeee7a77752 to your computer and use it in GitHub Desktop.
recycler adapter and data
This file contains hidden or 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
@BindingAdapter("bind_items") | |
fun setBindiItems(view : RecyclerView, itesm : List<Item>) { | |
val adapter = view.adapter as? MainAdapter ?: ItemAdapter().apply { view.adapter = this } | |
adapter.items = items | |
adapter.notifyDatasetChanged() | |
} |
This file contains hidden or 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
class ItemAdapter : RecyclerView.Adapter() { | |
var items : List<Item> = emptyList() | |
} |
This file contains hidden or 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
class MainViewModel { | |
val items = ObservableArrayList() | |
init { | |
items.add(Item("John")) | |
items.add(Item("Charles")) | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<data> | |
<variable name="vm" type="MainViewModel" /> | |
</data> | |
<android.support.v7.widget.RecyclerView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:bind_items="@{vm.items} /> | |
</layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for your medium post.
reporting small typo in databindingutils.kt
itesm ==> items