• 使用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);
        }
    }
    至此就可以完成了 一个简单的刷新!


  • 相关阅读:
    reflow和repaint
    移动端事件
    不支持冒泡的事件
    Gulp
    JAVAWEB项目Tomcat与内网穿透实现外网访问,可连接mysql数据库
    Echarts连接Mysql使用心得
    layui的date组件在弹窗里闪退的解决办法
    Layui的table标签使用记录
    Layui后台实现页面内部的iframe跳转
    第16周作业
  • 原文地址:https://www.cnblogs.com/android-host/p/5280518.html
Copyright © 2020-2023  润新知