211 RecyclerView Database Example |

  • 6 年前
Launch Your First Android app with our TOP course at 82% OFF (24 hrs ONLY) HERE \r
This video shows how to display data from database inside RecyclerView. In our case, we need to display data from Realm database inside our RecyclerView with the help of the RecyclerView.Adapter. The onCreateViewHolder is called initially when a row needs to be displayed for a few times and then the onBindViewHolder is called for all subsequent iterations. Create an Application subclass and override the onCreate method to define a RealmConfiguration which we set as the default configuration. In the main ivity, we simply get an instance of Realm using getDefaultInstance using which we can query all the drops stored in our database asynchronously. We use a RealmChangeListener to be notified when the drops have finished loading from the database and store the results inside a RealmResults object. Finally we call notifyDataSetChanged method to refresh the RecyclerView as we add more items to it.

お勧め