RxBindings For Spinner?

﹥>﹥吖頭↗ 提交于 2019-12-05 15:04:14

问题


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
                    }
                });

or

RxTextView.textChanges(name)
            .subscribe(new Action1<String>() {
                @Override
                public void call(String value) {
                    // do some work with the updated text
                }
            });

now i am trying to do the same for android spinner. i want to listen for itemselected event. can anyone help?


回答1:


The items in the Spinner come from the Adapter associated with this view.

See the Spinners guide.

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:

Documentation: https://developer.android.com/guide/topics/ui/controls/spinner.html

RxBinding Documentation: https://github.com/JakeWharton/RxBinding/blob/31e02dcaca426e2ce440093b501e1a28fe1461f6/rxbinding/src/androidTest/java/com/jakewharton/rxbinding2/widget/RxAdapterViewTest.java

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());
    });


来源:https://stackoverflow.com/questions/43446747/rxbindings-for-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!