zoukankan      html  css  js  c++  java
  • Android 官方下拉刷新 SwipeRefreshLayout

    0.build.gradle

      compile 'com.android.support:support-v4:23+'

    1.布局文件  

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ListView
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </ListView>
    </android.support.v4.widget.SwipeRefreshLayout>

    2.java代码

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_3);
            ButterKnife.bind(this);
            /** 绑定事件 */
            swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    // 网络请求
                    request();
                }
            });

        // 第一次打开自动刷新
        swipeRefreshLayout.measure(0, 0);
        swipeRefreshLayout.setRefreshing(true);
        request();
        }
    
    
        private void request() {
            HttpUtil.getInstance().get(new HttpUtil.Builder()
                    .url("/scloudmenu/menu/16/list?key=&token=95af71ee-abb9-41cd-b8fd-f2f0a2bf16c0")
                    .params("currentPage", ++currentPage + "")
                    .callBackSuccess(new CallBackSuccess() {
                        @Override
                        public void onSuccess(String json) { //拿到请求数据,相当于 handleMessage() 中的处理
                            CloudMenuEntityList data = JsonUtil.fromJson(json, CloudMenuEntityList.class);
                            entityList.addAll(data.cloudMenuEntityList);
                            tv.setText(entityList.size() + "");
    
                            // 取消刷新效果
                            swipeRefreshLayout.setRefreshing(false);
                        }
                    })
            );
        }
    
    
  • 相关阅读:
    UVa532 Dungeon Master 三维迷宫
    6.4.2 走迷宫
    UVA 439 Knight Moves
    UVa784 Maze Exploration
    UVa657 The die is cast
    UVa572 Oil Deposits DFS求连通块
    UVa10562 Undraw the Trees
    UVa839 Not so Mobile
    327
    UVa699 The Falling Leaves
  • 原文地址:https://www.cnblogs.com/Westfalen/p/6776880.html
Copyright © 2011-2022 走看看