RxBindings for Spinner?

I am a new android and rxjava. I went through many examples where we listen to events with rxbindings. such as

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'm trying to do the same for android spinner. I want to listen to the event selected for the item. can anyone help?

+5
source share
1 answer

Elements in Spinner come from the adapter associated with this view.

See the Spinners manual.

To define a selection event handler for a counter, run the AdapterView.OnItemSelectedListener Interface and the corresponding onItemSelected (). For example, here is the implementation of the interface in 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/widView/xestestRxestestxxest

After searching for Spinner in the GitHub-Repository, I found an example for Spinner:

 RxAdapterView.itemSelections(spinner) .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(integer -> { Log.v("spinner", integer.toString()); }); 
+15
source

Source: https://habr.com/ru/post/1266808/


All Articles