• 使用PullToRefresh实现下拉刷新和上拉加载


    PullToRefresh是一套实现非常好的下拉刷新库,它支持:

    1.ListView

    2.ExpandableListView

    3.GridView

    4.WebView

    等多种常用的需要刷新的View类型,而且使用起来也十分方便。

    (下载地址:https://github.com/chrisbanes/Android-PullToRefresh)

    下载完成,将它导入到eclipse中,作为一个library导入到你的工程中就好了。

    一、废话少说,下拉刷新go。

     1.在你的布局文件中加上你想用的View就好了,比如这儿我想用一个支持下拉 刷新的ListView

       <com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto"
                android:id="@+id/all_question_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="5dp"
                android:dividerHeight="0dp"
                android:divider="@null"
                android:cacheColorHint="@android:color/transparent"
                android:listSelector="@null"
                android:background="@android:color/white"
                ptr:ptrHeaderTextColor="@android:color/black" />

    2. 在你的Activity代码中进行简单的设置:

    @ViewMapping(id = R.id.all_question_list)
        private PullToRefreshListView mRefreshListView;

    这样你就可以对PullToRefreshListView进行操作。

        mRefreshListView.setMode(PullToRefreshBase.Mode.BOTH);
            mRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
                @Override
                public void onPullDownToRefresh(PullToRefreshBase<ListView> listViewPullToRefreshBase) {
                    requestQuestionList(1);
                    Utils.resetRefreshLabel(getActivity(), mRefreshListView);
                }
    
                @Override
                public void onPullUpToRefresh(PullToRefreshBase<ListView> listViewPullToRefreshBase) {
                    if (mCurPage * PAGE_SIZE >= mTotal) {
                        Utils.setRefreshLabelToLast(getActivity(), mRefreshListView);
                        Utils.COMMON_HANDLER.sendMessageDelayed(
                                Message.obtain(Utils.COMMON_HANDLER, Utils.REFRESH_TO_COMPLETE, mRefreshListView), 500);
                    } else {
                        requestQuestionList(mCurPage + 1);
                    }
                }
            });
        }

    其中setMode为Mode.Both是既要要实现上拉,也要实现下拉。

    当下拉和上拉完成时记得执行如下语言:mRefreshListView.onRefreshComplete();

  • 相关阅读:
    pandas
    高性能的异步爬虫
    组件推荐Forloop.HtmlHelpers 用来实现MVC的js加载顺序
    MVC 表单防伪,自定义提示(AntiForgery.Validate)
    Dapper 多表(三表以上)查询小技巧
    layui记录
    java websocket中的ping-pong 机制
    图像读取Exif小知识,图像扶正,还原拍摄时的角度
    关于人脸识别引擎FaceRecognitionDotNet的实例
    .NET的关于人脸识别引擎分享(C#)
  • 原文地址:https://www.cnblogs.com/hupp/p/4795510.html
Copyright © 2020-2023  润新知