zoukankan      html  css  js  c++  java
  • SwipeRefreshLayout下拉刷新

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.goodness.test.MainActivity">
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:id="@+id/sw"
            android:layout_height="match_parent">
    
            <EditText
                android:id="@+id/et"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginEnd="10dp"
                android:layout_marginStart="10dp"
                android:hint="@string/app_name"
                android:textColor="@color/colorAccent"
                android:textColorHint="@color/colorAccent"
                android:textSize="50sp" />
        </android.support.v4.widget.SwipeRefreshLayout>
    
    </RelativeLayout>
    package com.goodness.test;
    
    
    import android.os.Bundle;
    import android.os.Handler;
    import android.support.v4.widget.SwipeRefreshLayout;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
        EditText editText;
        SwipeRefreshLayout swipeRefreshLayout;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            editText = (EditText) findViewById(R.id.et);
            swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.sw);
            swipeRefreshLayout.setOnRefreshListener(this);
        }
    
        @Override
        public void onRefresh() {
    
            swipeRefreshLayout.setRefreshing(true);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    int random = (int) (Math.random() * 100 + 1);
                    swipeRefreshLayout.setRefreshing(false);
                    //每次刷新显示不同的随机数
                    editText.setText(String.valueOf(random));
                }
            }, 1000);
        }
    }
  • 相关阅读:
    larave5.6 引入自定义函数库时,报错不能重复定义
    laravel获取当前认证用户登录
    淘宝免费ip地址查询导致服务堵死的坑
    this关键字
    Jsp Spring Security 权限管理系统
    spring secrity
    spring bean何时实例化
    Spring Security3 页面 权限标签
    Spring常用注解,自动扫描装配Bean
    java继承时,实例化子类,是否会默认调用父类构造方法
  • 原文地址:https://www.cnblogs.com/thankyouGod/p/6403648.html
Copyright © 2011-2022 走看看