上拉加载下拉刷新

匿名 (未验证) 提交于 2019-12-03 00:11:01

1 //下拉刷新 上拉加载 2 implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' 3 implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'

 1 <com.scwang.smartrefresh.layout.SmartRefreshLayout  2         android:id="@+id/srl_control"  3         android:layout_width="match_parent"  4         android:layout_height="match_parent"  5         app:srlAccentColor="@color/colorTransparent"  6         app:srlPrimaryColor="@color/colorTransparent"  7         app:srlEnablePreviewInEditMode="true">  8   9         <com.scwang.smartrefresh.layout.header.ClassicsHeader 10             android:layout_width="match_parent" 11             android:layout_height="wrap_content"/> 12  13  14         <LinearLayout 15             android:background="@color/colorTheme" 16             android:layout_width="match_parent" 17             android:layout_height="610dp"/> 18  19         <com.scwang.smartrefresh.layout.footer.ClassicsFooter 20             android:layout_width="match_parent" 21             android:layout_height="wrap_content"/> 22  23     </com.scwang.smartrefresh.layout.SmartRefreshLayout>

 1 private void initSmartRefresh(){  2         //下拉刷新  3         refreshLayout.setOnRefreshListener(new OnRefreshListener() {  4             @Override  5             public void onRefresh(RefreshLayout refreshlayout) {  6                 refreshlayout.setEnableRefresh(true); //启用刷新  7                 //刷新的事件逻辑  8                 try {  9                     Thread.sleep(3000); 10                     refreshlayout.finishRefresh();//结束刷新 11                 } catch (InterruptedException e) { 12                     e.printStackTrace(); 13                 } 14             } 15         }); 16  17         //上拉加载 18         refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() { 19             @Override 20             public void onLoadmore(RefreshLayout refreshlayout) { 21                 refreshlayout.setEnableLoadmore(true);//启用加载 22                 //加载的事件逻辑 23                 try { 24                     Thread.sleep(3000); 25                     refreshlayout.finishLoadmore(); //结束加载 26                 } catch (InterruptedException e) { 27                     e.printStackTrace(); 28                 } 29             } 30         }); 31     }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!