• Android控件(一)下拉刷新:SwipeRefreshLayout


    须要注意的是SwipeRefreshLayout以下仅仅能够有一个直接子节点。

    布局文件例如以下。

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="MergeRootFrame" >
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_container"
            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>
    </FrameLayout>

    主程序例如以下:

    package com.francis.swiperefreshlayouttest;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.widget.SwipeRefreshLayout;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    // 布局文件下。<android.support.v4.widget.SwipeRefreshLayout> 仅仅能有一个直接的子类
    //
    // 主要方法
    //        setOnRefreshListener(OnRefreshListener): 为布局加入一个Listener
    //        setRefreshing(boolean): 显示或隐藏刷新进度条
    //        isRefreshing(): 检查是否处于刷新状态
    //        setColorSchemeResource(): 设置进度条的颜色主题。最多能设置四种
    
    
    public class MyActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener{
        private SwipeRefreshLayout mSwipeLayout;
        private ListView mListView;
        private ArrayAdapter<String> mArrayAdapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_my);
            String[] strings = new String[] {"a","b","c","d"};
            mArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strings);
            mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
            mSwipeLayout.setOnRefreshListener(this);
            //载入颜色是循环播放的。仅仅要没有完毕刷新就会一直循环,color1>color2>color3>color4
            mSwipeLayout.setColorSchemeResources(
                    android.R.color.holo_blue_bright,
                    android.R.color.holo_green_light,
                    android.R.color.holo_orange_light,
                    android.R.color.holo_red_light);
            mListView = (ListView)findViewById(R.id.list);
            mListView.setAdapter(mArrayAdapter);
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.my, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            if (id == R.id.action_grid_view) {
                startActivity(new Intent(MyActivity.this,GridViewTest.class));
            }
            return super.onOptionsItemSelected(item);
        }
    
        @Override
        public void onRefresh() {
    
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    // 停止刷新
                    mSwipeLayout.setRefreshing(false);
    
                }
            }, 3000);
    
        }
    }
    


  • 相关阅读:
    NX CAM二次开发-UF_OPER_unload_path卸载刀路
    NX CAM二次开发-UF_PARAM_set_int_value不勾选侧面与底面余量一致
    NX CAM二次开发-UF_PARAM_set_subobj_ptr_value设置进给率
    NX CAM二次开发-UF_PARAM_set_double_value设置转数
    NX CAM二次开发-UF_NCGROUP_ask_object_of_name通过名称获得指定组(NCGroup)的TAG
    NX CAM二次开发-修改操作所属的刀具,几何体,程序组等
    VC++-OLE/COM将EXCEL导出PDF,ExcelBook.ExportAsFixedFormat
    VC++将PNG转成二进制文件,在将二进制文件转回PNG图片
    实例开发-NX二次开发批量设置体到图层工具
    NX-二次开发UFUN在面上创建等参数曲线UF_MODL_create_isocurve
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5275071.html
Copyright © 2020-2023  润新知