SwipeRefreshLayout简单使用

SwipeRefreshLayout简单使用Activity:importjava.text.DateFormat;importjava.util.Date;importandroid.os.Bundle;importandroid.os.Handler;importandroid.support.v4.widget.SwipeRefreshLayout;importandroid.support

大家好,又见面了,我是你们的朋友全栈君。

Activity:

import java.text.DateFormat;
import java.util.Date;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.widget.TextView;
import android.app.Activity;

public class SwipeRefreshActivity extends Activity implements OnRefreshListener{

private SwipeRefreshLayout swipeRefreshLayout;
private TextView dateTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
        dateTv = (TextView) findViewById(R.id.date);
        swipeRefreshLayout.setOnRefreshListener(this);
    }
@Override
public void onRefresh() {

swipeRefreshLayout.setRefreshing(true);
(new Handler()).postDelayed(new Runnable() {


@Override
public void run() {

swipeRefreshLayout.setRefreshing(false);
Date date = new Date(System.currentTimeMillis());
dateTv.setText(DateFormat.getDateTimeInstance().format(date));
}
}, 3000);
}
}


布局文件:


<android.support.v4.widget.SwipeRefreshLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    xmlns:tools=”http://schemas.android.com/tools”
    android:id=”@+id/refresh”
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    tools:context=”.SwipeRefreshActivity” >

    <ScrollView
        android:layout_width=”match_parent”
        android:layout_height=”match_parent” >

        <LinearLayout
            android:layout_width=”match_parent”
            android:layout_height=”wrap_content”
            android:orientation=”vertical” >

            <TextView
                android:layout_width=”wrap_content”
                android:layout_height=”wrap_content”
                android:text=”下拉刷新以产生当前日期” />

            <TextView
                android:id=”@+id/date”
                android:layout_width=”wrap_content”
                android:layout_height=”wrap_content”
                android:text=”日期” />
        </LinearLayout>
    </ScrollView>

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



感觉还是第三方的好,系统控件在不同版本系统上运行效果相差很大!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152940.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • label 的autosize属性

    label 的autosize属性label的autosize属性,显示不全的问题。转载于:https://www.cnblogs.com/sfbrzkh/p/4487911.html

    2022年5月20日
    29
  • Ubuntu下使用SSH 命令用于登录远程桌面

    Ubuntu下使用SSH 命令用于登录远程桌面问题描述基础:ssh命令连接step1:SSH程序的安装step2:服务器启动ssh服务step3:查询服务器的ip地址step4:在本地主机端ssh远程登录服务器step5:退出远程登录进阶:利用公钥省去口令输入step1生成密钥对step2复制公钥至服务器参考资料问题描述做DL的经常需要在一台电脑(本地主机)上写代码,另一台电脑(服务器…

    2022年10月21日
    0
  • HDU 4825 Xor Sum 字典树+位运算

    HDU 4825 Xor Sum 字典树+位运算

    2021年12月5日
    50
  • UE4插件共享汇总大全[通俗易懂]

    UE4插件共享汇总大全[通俗易懂]UE4插件共享汇总大全:这是我发现的一个UE4插件分享网站http://ni93.com/unity/forum.php?mod=forumdisplay&fid=2列表如下,可在分享网站搜索特定名字,获取相关资源呦~~后续会持续更新这个网站的资源呦~…

    2022年5月21日
    101
  • UML时序图简析[通俗易懂]

    UML时序图简析[通俗易懂]前言在嵌入式软件开发中,必然会遇到与其他控制板卡或者服务器通信的情况。比如,制作一个无线远程控制系统。系统分为,输入设备,云端服务器,执行设备。其中输入设备,用户可以通过设备上的触摸屏进行交互,控制或者监测远程设备云端服务器,收发终端,接收输入设备的命令,并将其转换为执行设备可识别的信号发送到可执行设备。执行设备,执行服务器发送过来的命令,并且反馈当前的设备的一些状态.简单如下图所示。一般,这样的系统需要多人共同协作完成,输入设备的开发人员负责输入设备开发,云端负责云端,执行端负责执行端

    2022年6月16日
    66
  • 二分图最大匹配 hdoj 1045「建议收藏」

    二分图最大匹配 hdoj 1045

    2022年1月26日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号