zoukankan      html  css  js  c++  java
  • google推出的SwipeRefreshLayout下拉刷新用法

     

    使用如下:

    1.先下载android-support-v4.jar最新版本,之前的版本是没有SwipeRefreshLayout下拉刷新控件的,如果已经更新,此步骤可省略。

    2.在xml文件中引用android.support.v4.widget.SwipeRefreshLayout控件,在里面可以放置任何一个控件,例如ListView,gridview等。

    [html] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. <android.support.v4.widget.SwipeRefreshLayout  
    2.     android:id="@+id/swipe_refresh"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent" >  
    5.   
    6.     <ListView  
    7.         android:id="@+id/listview"  
    8.         android:layout_width="match_parent"  
    9.         android:layout_height="match_parent" >  
    10.     </ListView>  
    11. </android.support.v4.widget.SwipeRefreshLayout>  

    3.在java文件中使用。

    1. /**  
    2.  * 主页  
    3.  * @author w.w  
    4.  */  
    5. public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {  
    6.   
    7.     /**  
    8.      * 给ListView添加下拉刷新  
    9.      */  
    10.     private SwipeRefreshLayout swipeLayout;  
    11.       
    12.     /**  
    13.      * ListView  
    14.      */  
    15.     private ListView listView;  
    16.       
    17.     /**  
    18.      * ListView适配器  
    19.      */  
    20.     private ListViewAdapter adapter;  
    21.       
    22.     private List<ItemInfo> infoList;  
    23.       
    24.     @Override  
    25.     protected void onCreate(Bundle savedInstanceState) {  
    26.         super.onCreate(savedInstanceState);  
    27.         setContentView(R.layout.activity_main);  
    28.   
    29.         swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);  
    30.         swipeLayout.setOnRefreshListener(this);  
    31.           
    32.         // 顶部刷新的样式  
    33.         swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,  
    34.                 android.R.color.holo_blue_bright, android.R.color.holo_orange_light);  
    35.   
    36.         infoList = new ArrayList<ItemInfo>();  
    37.         ItemInfo info = new ItemInfo();  
    38.         info.setName("coin");  
    39.         infoList.add(info);  
    40.         listView = (ListView) this.findViewById(R.id.listview);  
    41.         adapter = new ListViewAdapter(this, infoList);  
    42.         listView.setAdapter(adapter);  
    43.     }  
    44.   
    45.     public void onRefresh() {  
    46.         new Handler().postDelayed(new Runnable() {  
    47.             public void run() {  
    48.                 swipeLayout.setRefreshing(false);  
    49.                 ItemInfo info = new ItemInfo();  
    50.                 info.setName("coin-refresh");  
    51.                 infoList.add(info);  
    52.                 adapter.notifyDataSetChanged();  
    53.             }  
    54.         }, 500);  
    55.     }  
    56. }  
     

    demo下载地址:http://download.csdn.net/detail/xue_wei_love/7135315

    来源:http://blog.csdn.net/wwzqj/article/details/22790521

    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    子网掩码
    一个正则表达式:该正则表达式标示了后面有数字,但又不能是某特定数字的情况
    C++:STL标准入门汇总
    SOAP
    uva10236The Fibonacci Primes
    uvalive3209City Game
    uvalive3695Distant Galaxy
    uva11549Calculator Conundrum
    uva11078Open Credit System
    uvalive3295Counting Triangles
  • 原文地址:https://www.cnblogs.com/hudabing/p/3759767.html
Copyright © 2011-2022 走看看