我如何通过数据绑定将对象列表绑定到微调器

时间:2019-04-20 14:15:24

标签: android kotlin data-binding

我在xml中有一个微调框

 <Spinner
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/expense_category"
            android:entries="@{()->createExpenseViewModel.getAllSourceItems(1)}"
            app:layout_constraintStart_toStartOf="@+id/textView"
            android:layout_marginTop="20dp"
            app:layout_constraintTop_toBottomOf="@+id/textView" app:layout_constraintWidth_percent="0.7"
    />

createExpenseViewModel.getAllSourceItems(1)方法返回 包含自定义对象

的列表的LiveData列表

我只想将此对象的属性(即SourceName)绑定到此微调器,如何实现此功能?如果我写一个绑定适配器,我将不得不在setEntries方法内创建一个数组适配器,我不想创建该数组适配器,有没有绑定适配器的方法吗?

0 个答案:

没有答案