Paging (Arch. Comp.)
The Android Paging Library helps you load and display small data chunks at a time. Learn to use ObjectBox database with the Paging library from Android Architecture Components.
Using ObjectBoxDataSource
public class NotePagedViewModel extends ViewModel {
private LiveData<PagedList<Note>> noteLiveDataPaged;
public LiveData<PagedList<Note>> getNoteLiveDataPaged(Box<Note> notesBox) {
if (noteLiveDataPaged == null) {
// query all notes, sorted a-z by their text
Query<Note> query = notesBox.query().order(Note_.text).build();
// build LiveData
noteLiveDataPaged = new LivePagedListBuilder<>(
new ObjectBoxDataSource.Factory<>(query),
20 /* page size */
).build();
}
return noteLiveDataPaged;
}
}Next steps
Last updated
Was this helpful?