今天完成下拉加载更多的功能:
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshLayout) { refreshXiaLa("xiala"); smartRefreshLayout.finishRefresh(2000); } }); smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore(RefreshLayout refreshLayout) { Toast.makeText(inflater.getContext(),"正在加载",Toast.LENGTH_SHORT).show(); refreshXiaLa("more"); smartRefreshLayout.finishLoadMore(2000); } });
if(remore.equals("xiala")){ if(list.size()-15*page>=0){ if(list.size()-15*page>=15){ listfre=new ArrayList<>(); for(int i=15*page;i<15*page+15;i++){ listfre.add(list.get(i)); } } else{ for(int i=15*page;i<list.size();i++){ listfre.add(list.get(i)); } } recyclerAdapter2=new RecyclerAdapter2(listfre); recyclerAdapter2.notifyDataSetChanged(); recyclerView.setAdapter(recyclerAdapter2); Toast.makeText(rootView.getContext(),"刷新完成",Toast.LENGTH_SHORT).show(); page++; } else { Toast.makeText(rootView.getContext(),"已无更多刷新内容",Toast.LENGTH_SHORT).show(); } } else if(remore.equals("more")){ if(page-page2==1){ page2++; } if(list.size()-15*page2>=0){ if(list.size()-15*page>=15){ for(int i=15*page;i<15*page+15;i++){ listfre.add(list.get(i)); } } else{ for(int i=15*page;i<list.size();i++){ listfre.add(list.get(i)); } } recyclerAdapter2=new RecyclerAdapter2(listfre); recyclerAdapter2.notifyDataSetChanged(); recyclerView.setAdapter(recyclerAdapter2); page2++; } else{ Toast.makeText(rootView.getContext(),"已经到底了",Toast.LENGTH_SHORT).show(); } }
完成了上拉和下拉的功能