【发布时间】:2021-11-20 19:13:43
【问题描述】:
所以我试图在同一个片段中填充两个 Spinner,两者都使用相同的列表,但显示不同的项目。
我有以下数据类:
data class ProductTypeObject (
//ProductType fields (2 fields)
var productType: String = "",
var productGroup: String = "",
@ServerTimestamp
var dateEditedTimestamp: Date? = null,
@Exclude @set:Exclude @get:Exclude
var productTypeID: String = ""
) : Serializable {
override fun toString(): String {
return productType
}
}
当从 ViewModel 观察列表时,Spinner 填充在 Fragment 中,如下所示:
// Observe ProductTypes and populate Spinner
businessViewModel.allAppDataProductTypes.observe(viewLifecycleOwner, Observer { productTypeArrayList ->
if (!productTypeArrayList.isNullOrEmpty()){
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, productTypeArrayList)
binding.inventoryAddEditProductGroupSpinner.adapter = adapter
}
})
这显示了product types as I have specified this in the toString()of the object, but is there a way to direct a second Spinner to show a list ofproduct group 的列表?
【问题讨论】:
标签: kotlin arraylist android-arrayadapter android-spinner