Created
February 1, 2021 22:50
-
-
Save longv/3f39413108d169fe02b9848f82d31d55 to your computer and use it in GitHub Desktop.
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
class MainActivity { | |
// ... | |
private val viewModel by viewModels { viewModelFactory } | |
private lateinit var adapter: DataBindingAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
adapter = DataBindingAdapter() | |
recyclerView.layoutManager = LinearLayoutManager(context) | |
recyclerView.adapter = adapter | |
observeData() | |
} | |
private fun observeData() { | |
viewModel.items.observe(this) { items -> | |
val bindingEntries = items.map { item -> | |
DataBindingEntry(R.layout.main_item, mapOf(BR.item, item)) | |
} | |
adapter.update(bindingEntries) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment