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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MybatisPlus自定义sql分页查询

    MybatisPlus自定义sql分页查询mybatisplus自定义sql分页查询

    2022年6月26日
    86
  • 视频编码格式不支持_缺少编码解码器

    视频编码格式不支持_缺少编码解码器AVI格式视频文件编码格式缺少编码解释器且该项目的编码格式不受支持产生0xc00d5212错误(见下图)解决方案:将AVI格式视频转换为MP4格式视频文件。方式:通过格式工厂软件(见下图)。下载链接:点击下载格式工厂4.8.0.0官方免费版操作:一、下载好软件(格式工厂)之后,点击启动软件进去,点击红色箭头指向的红色框的内容(->MP4)。二、点击红色箭头指向的红色框的…

    2022年9月30日
    4
  • PXE启动服务器及客户端镜像制作

    PXE启动服务器及客户端镜像制作基于CentOS6的PXE无盘系统制作,包含服务器端必要服务的设置开启,客户端镜像文件系统,根文件系统的制作,PXE选单的制作.

    2022年6月17日
    81
  • securecrt乱码解决方法[通俗易懂]

    设置securecrt属性。问题securecrt连接某台linux机器显示中文乱码解决方法菜单下option-&gt;sessionoption1.选择图中属性结构中Emulation属性,修改terminal改成linux2.选择Appearance,在字符集属性中选择utf-8(具体要根据linux环境而定)…

    2022年4月10日
    43
  • 计算距离矩阵的方法_距离矩阵计算

    计算距离矩阵的方法_距离矩阵计算给定一个 N 行 M 列的 01 矩阵 A,A[i][j] 与 A[k][l] 之间的曼哈顿距离定义为:dist(A[i][j],A[k][l])=|i−k|+|j−l|输出一个 N 行 M 列的整数矩阵 B,其中:B[i][j]=min1≤x≤N,1≤y≤M,A[x][y]=1dist(A[i][j],A[x][y])输入格式第一行两个整数 N,M。接下来一个 N 行 M 列的 01 矩阵,数字之间没有空格。输出格式一个 N 行 M 列的矩阵 B,相邻两个整数之间用一个空格隔开。数据范围

    2022年8月9日
    10
  • PHP 执行时间Fatal error: Maximum execution time of…

    PHP 执行时间Fatal error: Maximum execution time of…

    2022年3月8日
    40

发表回复

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

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