xml:
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/srfl" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/rlv" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> </android.support.v4.widget.SwipeRefreshLayout>
Java代码:
srfl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "更新了", Toast.LENGTH_SHORT).show(); //刷新完成 srfl.setRefreshing(false); } }, 2000); } }); mRlv.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); //可见的条目 int childCount = mRlv.getChildCount(); int itemCount = linearLayoutManager.getItemCount(); int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition(); if(firstVisibleItemPosition+childCount==itemCount){ Toast.makeText(MainActivity.this, "正在加载...", Toast.LENGTH_SHORT).show(); initData(); adapter.notifyDataSetChanged(); } } });