zoukankan      html  css  js  c++  java
  • 使用Google API 下拉刷新或者增加数据 SwipeRefreshLayout

    贴出布局代码:

    <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/id_swipe_ly"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:clickable="true">
                <TextView
                    android:id="@+id/id_listview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="按钮"/>
            </LinearLayout>
        </android.support.v4.widget.SwipeRefreshLayout>

    根据我的不完全实验 SwipeRefreshLayout 内可以使用所有控件,但是前提是必须在不能点击的控件上 写上这个 android:clickable=“true”  ,不然会有些问题。虽然数据依然能加载出来但是加载图标就会闪现(可以随意尝试)

    使用这个 SwipeRefreshLayout 必须实现这个接口:

    public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener  
    然后会自动生成它的一个方法:
    public void onRefresh() {

    }
    可以在这里面写你的一系列操作,但是不建议写耗时的操作,可以写一个Handler 来接收信息 并加载信息。

    全部代码:
    布局文件
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/id_swipe_ly"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:clickable="true">
                <TextView
                    android:id="@+id/id_listview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="按钮"/>
            </LinearLayout>
        </android.support.v4.widget.SwipeRefreshLayout>
    </RelativeLayout>

    MainAcitivity

    public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
    
        private static final int REFRESH_COMPLETE = 0X110;
        private SwipeRefreshLayout mSwipeLayout;
        private TextView mListView;
    
        private Handler mHandler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                switch (msg.what) {
                    case REFRESH_COMPLETE:
    
                        mListView.setText("猪猪侠");
                        mSwipeLayout.setRefreshing(false);
                        break;
    
                }
            }
    
            ;
        };
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mListView = (TextView) findViewById(R.id.id_listview);
            mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly);
    
            mSwipeLayout.setOnRefreshListener(this);
            mSwipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
                    android.R.color.holo_orange_light, android.R.color.holo_red_light);
        }
    
        public void onRefresh() {
    
            mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);
        }
    }
    至此就可以完成了 一个简单的刷新!


  • 相关阅读:
    IDEA中好用的插件
    Win10安装Docker
    win10系统关闭此电脑的文件夹
    postgreSQL主键自增长
    【设计模式】工厂模式
    vue2.0实现倒计时的插件(时间戳 刷新 跳转 都不影响),转载
    springCloud中的组件学习
    使用springBoot+jsp+redis解决单一用户问题
    使用HtmlUnit动态获取网页数据
    java爬取网站中所有网页的源代码和链接
  • 原文地址:https://www.cnblogs.com/android-host/p/5280518.html
Copyright © 2011-2022 走看看