今天对团队作业新闻APP添加上拉刷新功能。
具体实现:
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshLayout) { refreshXiaLa("xiala"); smartRefreshLayout.finishRefresh(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(); } }
可以实现新闻的下拉刷新