Recycle请求到数据后(还没有请求数据的话看上一篇);
首先是下拉:
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swiperefreshlayout" android:layout_width="match_parent" android:layout_below="@id/title2" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android:id="@+id/id_recyclerview" android:divider="#ffff0000" android:dividerHeight="10dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v4.widget.SwipeRefreshLayout>
这是下拉的样式
然后是下拉的方法
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { i++; String mpath2 = mpath + "&size=30&offset=" + i * 30; initData(mpath2); mSwipeRefreshLayout.setRefreshing(false); } });
这里i是要从那条开始儿设置的;自己可以根据自己的数据修改;
上拉这里是到底部自动加载,没有转圈的画面;
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); int position = manager.findLastVisibleItemPosition(); Log.d("main",position+" "+mDatas.size()); if(position>=mDatas.size()-1){ Toast.makeText(MainActivity.this, "到底了", Toast.LENGTH_SHORT).show(); } } });
来源:https://www.cnblogs.com/cainiaodongdong/p/7682129.html