Skip to content

Instantly share code, notes, and snippets.

@Haldir65
Last active February 7, 2016 02:30
Show Gist options
  • Save Haldir65/c17b91f0f2027d6abd35 to your computer and use it in GitHub Desktop.
Save Haldir65/c17b91f0f2027d6abd35 to your computer and use it in GitHub Desktop.
mRecyclerView= (RecyclerView) findViewById(R.id.recyclerview);
layoutManager=new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
adapter=new SimpleAdapter(this,mDatas);
mRecyclerView.setAdapter(adapter);
mSwipeRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout);
mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_red_light);
//此处是android自带的只支持下拉刷新
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
handler.sendEmptyMessageDelayed(MSG_COMPLETE, 3000);
}
});
//此处我们是对recyclerview添加scrollListener ,监听滑倒最后一个可见的条目的时候,刷新加载数据
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
//SCROLL_STATE_DRAGGING 和 SCROLL_STATE_IDLE 两种效果自己看着来
if(newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == adapter.getItemCount()){
mSwipeRefreshLayout.setRefreshing(true);
handler.sendEmptyMessageDelayed(MSG_COMPLETE,3000);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
lastVisibleItem=layoutManager.findLastVisibleItemPosition();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment