问题
I'm initializing a recyclerView using a room local database but it's taking too much time. The recycler view is in a view pager and it takes a lot of time to load. It also blocks the page and avoids the user to click on the other widgets of the view while loading. Is there a way to avoid it to block the application and to make to loading faster?
cashflows.apply {
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
itemsOM = mutableListOf<TransactionItem>()
if ( viewModel.omTransactions.size>0){
cashflows.visibility=View.VISIBLE
} else {
cashflows.visibility=View.GONE
text_placeholder.text=resources.getString(R.string.no_cashflow)
}
// Make sure we cancel the previous job before creating a new one
lifecycleScope.launch {
viewModel.omTransactions.forEach {
if (it.transaction?.transactionService != ENUMSERVICE.SOLDERESTANTORANGE) {
itemsOM.add(TransactionItem(custumSMS = it, home = true))
}
}
adapter = GroupAdapter<ViewHolder>().apply {
add(Section(itemsOM))
}
}
}
来源:https://stackoverflow.com/questions/62473686/initialisation-of-recycler-view-with-room-taking-too-much-time-and-recycler-view