PulltoRefreshListview

<com.handmark.pulltorefresh.library.PullToRefreshListView
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:id="@+id/pull_listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ptr:ptrDrawable="@drawable/default_ptr_flip"
    ptr:ptrAnimationStyle="flip"
    ptr:ptrHeaderBackground="#383838"
    ptr:ptrHeaderTextColor="#FFFFFF"
    >

</com.handmark.pulltorefresh.library.PullToRefreshListView>
 
 
 xmlns:ptr="http://schemas.android.com/apk/res-auto" 命名的控件
 ptr:ptrDrawable="@drawable/default_ptr_flip":刷新时显示的图片
ptr:ptrAnimationStyle="flip":刷新的图片以何种方式显示出来
ptr:ptrHeaderBackground="#383838":刷新时头部的布局
ptr:ptrHeaderTextColor="#FFFFFF":刷新时头部字体的颜色
com.github.userswlwork:pull-to-refresh:1.0.0
//获得资源ID
pullToRefreshListView = view.findViewById(R.id.pull_listview);


//设置头部底部的视图
//2.设置模式   BOTH 可以上拉 下拉  pull_from_end代表上拉,pull_from_start代表下拉
pullToRefreshListView.setMode(PullToRefreshBase.Mode.BOTH);
//3.都是布尔类型  第一个如果为true 时  当前设置的就是头部  如果第二个为true设置的就是底部
//先请求上拉刷新
final ILoadingLayout startLoading= pullToRefreshListView.getLoadingLayoutProxy(true, false);
startLoading.setPullLabel("下拉刷新");
startLoading.setRefreshingLabel("正在刷新");
startLoading.setReleaseLabel("放开刷新");

ILoadingLayout endLoading = pullToRefreshListView.getLoadingLayoutProxy(false, true);
endLoading.setPullLabel("上拉加载");
endLoading.setRefreshingLabel("正在加载");
endLoading.setReleaseLabel("放开加载");

//4.接口回调上拉下拉
pullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
        page = 1;
        getDatas();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //必须在异步中完成  在列表没有数据的时候,不再请求接口,调用当前方法
                pullToRefreshListView.onRefreshComplete();
            }
        },2000);

        //可以设置刷新的时间....
        startLoading.setLastUpdatedLabel("上次更新时间:"+new SimpleDateFormat("HH:mm").format(new Date(System.currentTimeMillis())));//last最近的,最后一次update修改/更新
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
        page+=1;
        getDatas();
        //12.
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                pullToRefreshListView.onRefreshComplete();
            }
        },2000);
    }
});

adapter1 = new MyAdapter(list,getActivity());
pullToRefreshListView.setAdapter(adapter1);

猜你喜欢

转载自blog.csdn.net/qq_41663420/article/details/80793917