zoukankan      html  css  js  c++  java
  • SwipeRefreshLayout下拉刷新简单用例

    自己的下拉刷新组件

    下拉刷新并自动添加数据

    MainActivity
    package com.shaoxin.myswiperefreshlayout;
    
    import android.graphics.Color;
    import android.os.Bundle;
    import android.support.v4.widget.SwipeRefreshLayout;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class MainActivity extends AppCompatActivity {
        private SwipeRefreshLayout swipeRefresh;
        private ListView list;
        private List listdata;
        private ArrayAdapter arrayAdapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
            list = (ListView) findViewById(R.id.list);
            listdata = new ArrayList();
            listdata.add("Java");
            listdata.add("C");
            listdata.add("phytson");
            listdata.add("Java");
            swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    listdata.add("nihao");
                    arrayAdapter.notifyDataSetChanged();
                    swipeRefresh.setRefreshing(false);
                }
            });
            swipeRefresh.setColorSchemeColors(Color.RED);
            swipeRefresh.setBackgroundColor(Color.GRAY);
            arrayAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, listdata);
            list.setAdapter(arrayAdapter);
    
        }
    }

    activity_main.xml

    <?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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.shaoxin.myswiperefreshlayout.MainActivity">
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeRefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"></ListView>
        </android.support.v4.widget.SwipeRefreshLayout>
    </RelativeLayout>
  • 相关阅读:
    postman批量运行和参数化
    Loadrunner 参数化数据分配方法以及数据更新方式
    常用函数
    获取 layer.msg 弹窗的信息
    登录页脚本小结
    关于linux下system()函数的总结
    请不要重复犯我在学习Python和Linux系统上的错误
    教你摸清 Linux PC 的性能底细?
    Ubuntu GNOME 16.10 Beta 1问世了!
    Google疯了,竟然这样!
  • 原文地址:https://www.cnblogs.com/ShaoXin/p/6171423.html
Copyright © 2011-2022 走看看