You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A library for for simplifying adapter creation, support List, RecyclerView, ViewPager.
Content
ViewHolder
publicclassDataGetter<T> {
finalpublicTprevious;
finalpublicTnext;
finalpublicTdata;
publicDataGetter(Tprevious, Tdata, Tnext) {
this.previous = previous;
this.next = next;
this.data = data;
}
}
publicinterfaceIViewHolder<T> {
// create view and bind to this view holdervoidbind(Viewview);
// 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 allvoidonDataChange(DataGetter<T> getter, intposition);
}
ViewCreator
publicinterfaceIViewCreator<T> {
// call in getViewViewview(ViewGroupcontainer);
// call in getItemViewTypeintviewTypeFor(Tdata, intposition, intitemCount);
// call in getViewTypeCountintviewTypeCount();
}
Single Layout
// ViewCreator just a implement of IViewCreator, accept layout id and view holder factorynewAutoListAdapter(items, newViewCreator(R.layout.list_item, () -> newViewHolder());
Multiple Layout
// ViewCreatorCollection just another implement of IViewCreator, it create different view depends on values of item and position and itemCount.// It useful when getViewTypeCount > 1ViewCreatorCollection<DataType> collection = newViewCreatorCollection.Builder<DataType>()
.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();
newAutoListAdapter(items, collection);
Paging ListView
ViewCreatorCollectioncollection = newViewCreatorCollection.Builder<DataType>()
.loadingResId(R.layout.list_item_loading)
.addFilter((data, position, itemCount) -> data != null, R.layout.list_item, ViewHolder::new)
.build();
// pagingListener will be called when arrive the last position in ListViewnewAutoListPagingAdapter<DataType>(stocks, collection, pagingListener);