Showing posts with label RxAndroid. Show all posts
Showing posts with label RxAndroid. Show all posts

RxAndroid Example to display data on RecyclerView in Android Studio

RxAndroid is simple in one term is reactive extension for android.
Android authorities defined, Observables and Observers in terms of RxAndrod, There are two basic and very important items in reactive programming, Observables and Observers. Observables publish values, while Observers subscribe to Observables, watching them and reacting when an Observable publishes a value.

In simpler terms:

    An Observable performs some action, and publishes the result.
    An Observer waits and watches the Observable, and reacts whenever the Observable publishes results.

There are three different changes that can occur on an Observable that the Observer reacts to. These are:


  1.     Publishing a value
  2.     Throwing an error
  3.     Completed publishing all values


A class that implements the Observer interface must provide methods for each of the three changes above:


  1.     An onNext() method that the Observable calls whenever it wishes to publish a new value
  2.     An onError() method that’s called exactly once, when an error occurs on the Observable.
  3.     An onCompleted() method that’s called exactly once, when the Observable completes execution.

Example: Display list of data using RxAndroid in to RecyclerView

First you have to import the dependencies  latest version of RxAndrod, RxJava and other like recyclerview, in to the build.gradle on app level inside the dependencies section.


Layout:
 RecyclerView is simply A flexible view for providing a limited window into a large data set.
activity_main.xml


and custom list item layout



Now, Obserable implement on MainActivity,



and Now implement RecyclerView Adapter



Output looks like:


Download full code from github: RxAndroid_RecyclerView_Example

Happy Coding!!!