Slide 69
Slide 69 text
class ObservableRecyclerAdapter extends RecyclerView.Adapter {
private final Context context;
private final ObservableList items;
ObservableRecyclerAdapter(Context context, ObservableList items) {
this.context = context;
this.items = items;
// Add listener to ObservableList
items.addOnListChangedCallback(new ObservableList.OnListChangedCallback>() {
@Override
public void onChanged(ObservableList items) {
notifyDataSetChanged();
}
@Override
public void onItemRangeChanged(ObservableList items, int i, int i1) {
notifyItemRangeChanged(i, i1);
}
@Override
public void onItemRangeInserted(ObservableList items, int i, int i1) {
notifyItemRangeInserted(i, i1);
}
@Override
public void onItemRangeMoved(ObservableList items, int i, int i1, int i2) {
notifyItemMoved(i, i1)
}
@Override
public void onItemRangeRemoved(ObservableList items, int i, int i1) {
notifyItemRangeRemoved(i, i1);
}
});
}
//...
}