A library for for simplifying adapter creation, support List, RecyclerView, ViewPager.
public class DataGetter {
final public T previous;
final public T next;
final public T data;
public DataGetter(T previous, T data, T next) {
this.previous = previous;
this.next = next;
this.data = data;
}
}
public interface IViewHolder {
// create view and bind to this view holder
void bind(View view);
// position: item position in list
// getter: access current item and previous and next, this is useful when decide show or hide some view depened on previous item or next item or all
void onDataChange(DataGetter getter, int position);
}
public interface IViewCreator {
// call in getView
View view(ViewGroup container);
// call in getItemViewType
int viewTypeFor(T data, int position, int itemCount);
// call in getViewTypeCount
int viewTypeCount();
}
// ViewCreator just a implement of IViewCreator, accept layout id and view holder factory
new AutoListAdapter(items, new ViewCreator(R.layout.list_item, () -> new ViewHolder());
// ViewCreatorCollection just another implement of IViewCreator, it create different view depends on values of item and position and itemCount.
// It useful when getViewTypeCount > 1
ViewCreatorCollection collection = new ViewCreatorCollection.Builder()
.addFilter(data, position, itemCount) -> position == 1, R.layout.list_item_1, ViewHolder1::new)
.addFilter((data, position, itemCount) -> position == 2, R.layout.list_item_2, ViewHolder2::new).build();
new AutoListAdapter(items, collection);
ViewCreatorCollection collection = new ViewCreatorCollection.Builder()
.loadingResId(R.layout.list_item_loading)
.addFilter(R.layout.list_item, ViewHolder::new)
.build();
// pagingListener will be called when arrive the last position in ListView
new AutoListPagingAdapter(stocks, collection, pagingListener);
dependencies {
compile 'com.benny.library:autoadapter:0.2.8'
}QQ Group: 516157585