本文介绍了微调监听器LiveData问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的片段中,我有两个微调工具。
两者都由在ViewModel中观察到的LiveData填充,如下所示:
数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假"> // Observe Filtered ProductGroups and populate Spinner
businessViewModel.filteredAppDataProductGroups.observe(viewLifecycleOwner, { productGroupArrayList ->
if (!productGroupArrayList.isNullOrEmpty()){
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, productGroupArrayList)
binding.inventoryAddEditProductGroupSpinner.adapter = adapter
}
})
// Observe Filtered ProductTypes and populate Spinner
businessViewModel.filteredAppDataProductTypes.observe(viewLifecycleOwner, { productTypeArrayList ->
if (productTypeArrayList != null){
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, productTypeArrayList)
binding.inventoryAddEditProductTypeSpinner.adapter = adapter
}
})