use of com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener in project SmartRefreshLayout by scwang90.
the class RepastPracticeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_repast);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setEnableFooterFollowWhenLoadFinished(true);
// 第一次进入演示刷新
if (isFirstEnter) {
isFirstEnter = false;
refreshLayout.autoRefresh();
}
// 初始化列表和监听
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter<Model>(loadModels(), R.layout.listitem_practice_repast) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Model model, int position) {
holder.text(R.id.name, model.name);
holder.text(R.id.nickname, model.nickname);
holder.image(R.id.image, model.imageId);
holder.image(R.id.avatar, model.avatarId);
}
});
refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.finishRefresh();
// 恢复上拉状态
refreshLayout.setNoMoreData(false);
}
}, 2000);
}
@Override
public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
if (mAdapter.getCount() > 12) {
Toast.makeText(getBaseContext(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
// 设置之后,将不会再触发加载事件
refreshLayout.finishLoadMoreWithNoMoreData();
} else {
mAdapter.loadMore(loadModels());
refreshLayout.finishLoadMore();
}
}
}, 1000);
}
});
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.setHeaderInsetStart(DensityUtil.px2dp(toolbar.getHeight()));
}
}, 500);
}
// 状态栏透明和间距处理
StatusBarUtil.darkMode(this);
StatusBarUtil.setPaddingSmart(this, view);
StatusBarUtil.setPaddingSmart(this, toolbar);
StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
Aggregations