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


相关推荐

  • java程序设计实验报告_c++程序设计实验指导答案

    java程序设计实验报告_c++程序设计实验指导答案前言一般我们写接口自动化的时候,遇到复杂的逻辑,都会调用API方法来满足前置条件,Pytest的特性是无法用例之间相互调动的,我们一般只调用自己封装的API方法。而httprunner支持用例之间

    2022年7月30日
    5
  • 大话数据结构学习心得

    大话数据结构学习心得想重温一下数据结构和算法,选择了大话数据结构这本书。本书用趣味的方式介绍了数据结构起源、算法设计,线性表、栈与队列、串、树、图、查找、排序。对于当前用高级语言(java,c#,python等)开发的软件开发人员来说可能相关内容涉及不到,因为高级语言已经封装好了相关方法。但是了解了计算机内存存储、查找、排序等算法对于开发人员来说会有一个新的认识:例如如何优化方法提高存储速度、查询速度等。附:…

    2022年6月24日
    29
  • 使用vs2010生成SQL Server 随机数据

    使用vs2010生成SQL Server 随机数据

    2021年11月24日
    47
  • Java8新特性学习之一:lambda表达式入门

    Java8新特性学习之一:lambda表达式入门

    2021年8月3日
    70
  • cms漏洞扫描_大数据因果溯源分析

    cms漏洞扫描_大数据因果溯源分析CMS系统漏洞分析溯源(第5题)解题思路:登陆页面>>>扫描后台地址>>>登陆地址>>>查看是否可以绕过>>>不可以的话>>>百度管理系统源码>>>分析源码>>>查看登陆页面>>>找到相关php文件>>>admin_name>>>浏览器添加cookie>>>直接访问带有漏洞php文件的页面>>&

    2022年9月27日
    3
  • Java中&和&&,|和||的区别(超详细讲解),细节请必会!

    Java中&和&&,|和||的区别(超详细讲解),细节请必会!一、&是与,&&是短路与&&是左边条件不满足就终止了,不会继续计算右边条件;而&是无论左边是否满足都会继续执行右边。比如a&&b,假如计算a是假,那么就不会继续计算b的真假值了;假如a是真,那么会继续计算b,当b也是真时,a&&b为真。而a&b,无论a是真假,都会继续计算…

    2022年7月9日
    24

发表回复

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

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