RxBindings适用于微调器? [英] RxBindings For Spinner?
问题描述
我是新的android和rxjava.我已经看过很多例子,我们在其中侦听带有rxbindings的事件.像这样
i am new android and rxjava. i have been through many examples where we listen for events with rxbindings. such as this
RxView.clicks(b).subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
// do some work here
}
});
或
RxTextView.textChanges(name)
.subscribe(new Action1<String>() {
@Override
public void call(String value) {
// do some work with the updated text
}
});
现在我正在尝试对android微调器做同样的事情.我想听itemselected事件.有人可以帮忙吗?
now i am trying to do the same for android spinner. i want to listen for itemselected event. can anyone help?
推荐答案
微调器中的项目来自与此关联的适配器视图.
The items in the Spinner come from the Adapter associated with this view.
请参阅微调框指南.
要为微调框定义选择事件处理程序,请实施AdapterView.OnItemSelectedListener接口和相应的onItemSelected()回调方法.例如,这是一个接口在Activity中的实现:
To define the selection event handler for a spinner, implement the AdapterView.OnItemSelectedListener interface and the corresponding onItemSelected() callback method. For example, here's an implementation of the interface in an Activity:
文档: https://developer.android.com/guide/topic/ui/controls/spinner.html
RxBinding Documentation: https://github.com/JakeWharton/RxBinding/blob/31e02dcaca426e2ce440093b501e1a28fe1461f6/rxbinding/src/androidTest/java/com/jakewharton/rxbinding2/widget/RxAdapterViewTest.java
在GitHub-Repository中搜索Spinner之后,我找到了Spinner的示例:
After searching for Spinner in GitHub-Repository, I found an example for Spinner:
RxAdapterView.itemSelections(spinner)
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(integer -> {
Log.v("spinner", integer.toString());
});
这篇关于RxBindings适用于微调器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!