如何在Android中通过数据绑定获取当前的微调器值?

问题描述 投票:0回答:1

我正在Andriod中将MVVM模式与数据绑定一起使用。我将值设置为微调框,并且可以使用,但是如何在ViewModel中获取选定的项/位置?

java android data-binding spinner
1个回答
0
投票

您可以使用xml中的android:selectedItemPosition并将其绑定到ViewModel中的模型,例如以下示例

android:selectedItemPosition="@={viewModel.model.selectedPosition}"
© www.soinside.com 2019 - 2024. All rights reserved.