• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
山海1992
博客园    首页    新随笔    联系   管理    订阅  订阅

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);
}
});

posted @ 2017-03-22 17:12  山海1992  阅读(2170)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3