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);
        }
    }
  • 相关阅读:
    sizeof in C
    Get WIFI SSID and BSSID
    Swift和C混合Socket编程实现简单的ping命令&主机发现
    The different of bit Compiler
    Get all Ethernet information in Swift
    Get Local IP Address in Swift
    编译Unity3D Mono 加密DLL 填坑记
    spring-quartz 项目启动后执行一次job 之后按照规定时间执行job
    通过反射获取SSM的controller层的注解以及注解中的value值
    网页中高亮选中的关键字
  • 原文地址:https://www.cnblogs.com/thankyouGod/p/6403648.html
Copyright © 2011-2022 走看看