zoukankan      html  css  js  c++  java
  • SwipeRefreshLayout 配合fragment 下拉刷新的使用,超级简单

    前台demo

    <android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:id="@+id/swipe_container"
    android:layout_height="wrap_content"
    >
    <ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/test_record"
    android:layout_marginBottom="50dp"
    >
    </ListView>

    </android.support.v4.widget.SwipeRefreshLayout>

    后台的demo
    因为界面是fragment 并不是一个activity,所以后台demo写在了
    public void onActivityCreated(@Nullable Bundle savedInstanceState){}
    这个方法里面了,核心demo具体如下:
    注意事项,我原来一直无法刷新,是因为在方法onRefresh,里面没有写加载数据的方法,仔细想一想,
    做刷新处理,肯定是请求数据,所以,initScore(); 这个方法是直接请求数据。加进去就OK 了。

    mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
    mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
    my_record.setText("正在刷新");
    // TODO Auto-generated method stub
    test_type.clear();
    test_score.clear();
    test_time.clear();
    initScore();
    new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    my_record.setText("刷新完成");
    mSwipeLayout.setRefreshing(false);
    }
    }, 6000);
    }
    });

  • 相关阅读:
    AirtestIDE基本功能(二)
    AirtestIDE基本功能(一)
    Pycharm Debug功能详解
    AirtestIDE环境安装
    leetcode-338. 比特位计数
    leetcode-401. 二进制手表
    leetcode-392. 判断子序列
    leetcode-155. 最小栈
    leetcode-111. 二叉树的最小深度
    leetcode-110. 平衡二叉树
  • 原文地址:https://www.cnblogs.com/dreamboy1992/p/6600946.html
Copyright © 2011-2022 走看看