1.对原生的SwipeRefreshLayout 进行自定义

public class AutoSwipeRefreshLayout extends SwipeRefreshLayout {

public AutoSwipeRefreshLayout(Context context) {

super(context);

}

public AutoSwipeRefreshLayout(Context context, AttributeSet attrs) {

super(context, attrs);

}

/**

* 自动刷新

*/

public void autoRefresh() {

try {

Field mCircleView = SwipeRefreshLayout.class.getDeclaredField("mCircleView");

mCircleView.setAccessible(true);

View progress = (View) mCircleView.get(this);

progress.setVisibility(VISIBLE);

Method setRefreshing = SwipeRefreshLayout.class.getDeclaredMethod("setRefreshing", boolean.class, boolean.class);

setRefreshing.setAccessible(true);

setRefreshing.invoke(this, true, true);

} catch (Exception e) {

e.printStackTrace();

}

}

}

2.使用时直接调用autoRefresh()方法可以进行自动刷新

3.需要添加正在刷新或者正在加载的提示的情况: 可以再布局中,添加Textview实现

xml文件如下

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/tv_loading"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:padding="@dimen/dp_5" />

android:id="@+id/refresh_list"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/tv_no_content"

style="@style/title_second_setting"

android:layout_centerInParent="true"

android:layout_gravity="center"

android:layout_marginTop="@dimen/dp_20"

android:text="@string/no_content"

android:visibility="gone" />

android:id="@+id/lv_detail"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

4.实现代码:

refreshsetOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

@Override

public void onRefresh() {

tv_loading.setText(R.string.data_loading);

new Handler().postDelayed(new Runnable() {

@Override

public void run() {

// 添加需要刷新的数据

getdata();

refresh_order.setRefreshing(false);

if (total_page==0){

tv_loading.setVisibility(View.GONE);

tv_no_content.setVisibility(View.VISIBLE);

}

}

}, 3000);

}

});

android 页面计时器,Android中页面添加计时器进行的刷新相关推荐

  1. Android 在布局容器中动态添加控件

    这里,通过一个小demo,就可以掌握在布局容器中动态添加控件,以动态添加Button控件为例,添加其他控件同样道理. 1.addView 添加控件到布局容器 2.removeView 在布局容器中删掉 ...

  2. 【日常踩坑】Android机微信webview中页面跳转的问题

    今天分享一个前端君踩到的小坑,在webapp中,如果我们要代码实现刷新当前页面的话,相信很多人都习惯用: window.location.reload(); 使用 .reload() 方法实现刷新页面 ...

  3. timer计时器 java_java中基于timer计时器的图片播放

    packagecom.sxt.jtime;importjava.awt.BorderLayout;public class Itimer_test extendsJFrame {privateJPan ...

  4. python 计时器模块_python 如何添加计时器

    2016-05-17 回答 用python实现计时器功能,代码如下: ''' simple timing function. this function prints out a message wi ...

  5. vue 动态添加click_vue,在模块中动态添加dom节点,并监听

    vue向数组中动态添加数据 vue中数据更新通过v-model实现,向数组中添加数据通过push()实现,向shortcuts数组中动态添加newShortcut对象中的title和action th ...

  6. jQuery Mobile弹出对话框后不刷新原页面,保持原页面内容不变

    使用jQuery Mobile开发移动应用程序时,在一个页面上弹出对话框,关闭对话框后,发现原来的页面被刷新了.如果原页面上有一些已经选择或者填写的数据,则这些数据就会丢失.这时候,就需要对对话框的返 ...

  7. android viewpager动态加载页面,Android viewpager中动态添加view并实现伪无限循环的方法...

    本文实例讲述了Android viewpager中动态添加view并实现伪无限循环的方法.分享给大家供大家参考,具体如下: viewpager的使用,大家都熟悉,它可以实现页面之间左右滑动的切换,这里 ...

  8. 仿天猫 购物车(Android studio 仿天猫 详情页面 添加购物车选择 颜色 尺寸demo)

    这是我第一次编写博客,有不好的地方请发邮件或留言告知. 注*请勿转载-转载需博主同意 1.首先就是设计页面了–先效果图 2.现在开始看代码,没有啥好说的 这是布局文件 MainActivity 里面的 ...

  9. android 关于页面,解析android中的帮助、about、关于作者、HELP等提示页面

    在android中,经常要用到帮助.about.关于作者等的提示页面. 类似这样的页面: 这样的页面,我们可以通过AlertDialog对话框来设计. 设计一个AboutDialog类继承于Alert ...

最新文章

  1. 大数据,正在到来的数据革命——涂子沛
  2. 武装机器狗不会自主杀人,监管自主杀伤性武器是政府的事,机器狗公司CEO这样说...
  3. 在VisualState状态里更改Grid的列宽之类的
  4. 轻量级RTSP服务和内置RTSP网关的区别和联系
  5. CVPR 2020 | 基于知识蒸馏的分块监督NAS
  6. Uncaught ReferenceError: FileAsyncWriter is not defined
  7. ES和Kibana在docker中的安装
  8. 超实用Mac软件分享
  9. 洛谷 P2495 [SDOI2011]消耗战
  10. bulkwrite 批量插入_使用EF扩展EntityFramework.BulkInsert实现批量插入
  11. Excel连接数据库
  12. Make Cents? Gym - 101350M (水)
  13. 美股投资指南 – 网上美股开户其实很简单
  14. 美赛BOOM数学建模1-2蒙特卡洛法
  15. L1-020 帅到没朋友(Python3)
  16. matlab对非平稳一维信号的小波变换
  17. xp系统禁用wmi服务器,xp中哪些服务是可以关闭的
  18. 零基础软件开发培训靠谱吗?
  19. Germaine的安装
  20. (一)深度学习项目代码结构

热门文章

  1. 借助Docker,在win10下编码,一键在Linux下测试
  2. pip: command not found
  3. 如何使用 stack?- 每天5分钟玩转 Docker 容器技术(112)
  4. Mapreduce 进阶
  5. Javascript 调用百度地图不显示
  6. DAY04 WINDOWS 文件的共享以及FTP服务器的搭建
  7. eclipse编译android工程提示无翻译字符串错误的忽略方法
  8. 设计模式---状态模式
  9. echarts 折线图阴影颜色渐变
  10. Unity WebGL打包微端时遇到的indexedDB加载问题