ObjectAdapter提供对数据模型的访问,其内部有观察者,数据的改变,会通知UI更新。ObjectAdapter是一个抽象类,其实现还得看ArrayObjectAdapter或CursorObjectAdapter
//设置PresenterSelector
public ObjectAdapter(PresenterSelector presenterSelector) {
setPresenterSelector(presenterSelector);
}
//设置Presenter,会转化为SinglePresenterSelector
public ObjectAdapter(Presenter presenter) {
setPresenterSelector(new SinglePresenterSelector(presenter));
}
//设置PresenterSelector通过item获取对应的Presenter
public final Presenter getPresenter(Object item) {
if (mPresenterSelector == null) {
throw new IllegalStateException("Presenter selector must not be null");
}
return mPresenterSelector.getPresenter(item);
}
//需要子类实现
public abstract Object get(int position);
ArrayObjectAdapter 主要提供了一个实体列表,提供了一系列数据列表更新的方法:add 、addAll、remove、move、replace、removeItems、clear、setItems,setItems通过实现DiffCallback可以局部更新数据。
private final List<Object> mItems = new ArrayList<>();
//在ItemBridgeAdapter中 ObjectAdapter就是通过此方法拿到具体的item
@Override
public Object get(int index) {
return mItems.get(index);
}
网友评论