use of com.hpu.baserecyclerviewadapter.sample.multi.FourthItem in project BaseRecyclerViewAdapter by donghan0912.
the class StaggeredFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
refreshLayout.setEnabled(false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
for (int i = 0; i < 20; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list.add(new FourthItem(wq));
}
final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
recyclerView.setAdapter(adapter);
adapter.addHeader(new SimpleItem(R.layout.layout_staggered_head) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
// 设置加载更多布局,并占满整行
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
@Override
public void onLoadMore() {
if (!loadMore) {
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
List<FourthItem> list2 = new ArrayList<>();
for (int i = 0; i < 21; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list2.add(new FourthItem(wq));
}
list.addAll(list2);
if (list.size() > 70) {
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore_complete) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
loadMore = false;
}
adapter.addData(list2);
}
}, 3000);
}
}, 3000);
}
});
}
Aggregations