您的位置:首页 > 其它

PullToRefresh上拉刷新下拉加载更多的使用

2017-12-08 00:19 519 查看
1.这回就不用导包了    只需要添加依赖
https://pan.baidu.com/s/1o8rBnVs       密码:094e

当然你想写一个简单的上拉和下拉的话   就只要导这library一个依赖就行了

其他的三个只不过是高级版的   功能更多一些   

2.看图操作



3.看图操作



4.看图操作



5.看图操作



6.然后就是构建       在主函数中注册和设置Mode

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//注册pullTorefresh
Fresco.initialize(getApplicationContext());

//http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=10&page=1
lv=findViewById(R.id.lv);
//这句话必须写    不然你写的上拉加载数据没有任何效果
lv.setMode(PullToRefreshBase.Mode.BOTH);
lv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
//这是下拉刷新的方法
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

lv.postDelayed(new Runnable() {
@Override
public void run() {
lv.onRefreshComplete();
}
},2000);
}
//这是上拉加载更多的方法
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

lv.postDelayed(new Runnable() {
@Override
public void run() {
lv.onRefreshComplete();
}
},2000);

}
});

}


7.主布局         这个布局也是也可以写

com.handmark.pulltorefresh.library.PullToRefreshGridView这个布局   当然有很多的布局


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="comqq.example.hasee.myapplication.MainActivity"
android:orientation="vertical">
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.handmark.pulltorefresh.library.PullToRefreshListView>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐