• 一手遮天 Android


    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

    一手遮天 Android - view(RecyclerView): RecyclerView 下拉刷新(结合 SwipeRefreshLayout 控件实现)

    示例如下:

    /view/recyclerview/RecyclerViewDemo3.java

    /**
     * 演示 RecyclerView 的下拉刷新,结合 SwipeRefreshLayout 控件实现
     *
     *
     * 引入 SwipeRefreshLayout 控件的话,需要在 app 的 build.gradle 中配置好 implementation "androidx.swiperefreshlayout:swiperefreshlayout:x.x.x"
     */
    
    package com.webabcd.androiddemo.view.recyclerview;
    
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
    
    import android.os.Bundle;
    import android.os.Handler;
    
    import com.webabcd.androiddemo.R;
    
    public class RecyclerViewDemo3 extends AppCompatActivity {
    
        private RecyclerView _recyclerView;
        private SwipeRefreshLayout _swipeRefreshLayout1;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_view_recyclerview_recyclerviewdemo3);
    
            _recyclerView = findViewById(R.id.recyclerView1);
            _swipeRefreshLayout1 = findViewById(R.id.swipeRefreshLayout1);
    
            sample();
        }
    
        private void sample() {
    
            _recyclerView.setLayoutManager(new LinearLayoutManager(RecyclerViewDemo3.this));
            _recyclerView.setAdapter(new MyRecyclerViewAdapter(MyData.generateDataList()));
    
            // 下拉刷新提示动画的前景色
            _swipeRefreshLayout1.setColorSchemeResources(R.color.white);
            // 下拉刷新提示动画的背景色
            _swipeRefreshLayout1.setProgressBackgroundColorSchemeResource(R.color.orange);
            // 监听下拉刷新事件
            _swipeRefreshLayout1.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            // 隐藏下拉刷新提示动画
                            _swipeRefreshLayout1.setRefreshing(false);
    
                            // 更新 RecyclerView 的数据
                            ((MyRecyclerViewAdapter)_recyclerView.getAdapter()).updateData(MyData.generateDataList());
                            _recyclerView.getAdapter().notifyDataSetChanged();
                        }
                    },2000);
                }
            });
        }
    }
    

    /layout/activity_view_recyclerview_recyclerviewdemo3.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipeRefreshLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    
    </LinearLayout>
    

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

  • 相关阅读:
    (转)Linux系统中sysctl命令详解 sysctl -p、sysctl -a、sysctl -w
    EM2 MP1 Vowel and Consonant Teacher:Ashley
    Phonics 自然拼读法 y,x,ch,sh,(voiced)th/ð/ ,(unvoiced) th/θ/ Teacher:Lamb
    java列表转成 int[] 的格式
    分类模型评估之ROC-AUC曲线和PRC曲线
    hive 抽样方法
    AUC理解
    Spark性能调优——基础篇
    scala 稀疏向量
    scala 建模
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_recyclerview_RecyclerViewDemo3.html
Copyright © 2020-2023  润新知