zoukankan      html  css  js  c++  java
  • 使用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();

  • 相关阅读:
    《数据结构第一章复习》
    《图的基本操作》
    《矩阵的一些基本操作》
    <矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置>
    《两个二维数组(矩阵)相乘》
    C#隐藏与显示系统任务栏和开始菜单栏按钮
    C#通过窗体属性缩小一定尺寸时,无法再缩小窗体尺寸问题
    C#一个窗体调用另一个窗体的方法
    C#异步线程
    C#中MessageBox.Show问题(让提示窗口不显示在任务栏中)
  • 原文地址:https://www.cnblogs.com/hupp/p/4795510.html
Copyright © 2011-2022 走看看