最簡單下拉刷新,Google最新(可刷新任何控件)

    Google終於出下拉刷新控件了,你們知道嗎? 2014年3月29日


XML文件需要引用android.support.v4.widget.SwipeRefreshLayout控件,在裏面

可以放置任何一個控件,包括ListView,scrollview,gridview等

等,。都可以下拉刷新。。。。。。

main_activity.xml代碼:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
   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>

MainActivity.java
/*
* Created by Storm Zhang, Mar 31, 2014.
*/

package com.storm.swiperefreshlayoutdemo;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView;

public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {

private SwipeRefreshLayout swipeLayout;
private ListView listView;
private ListViewAdapter adapter;
private ArrayList<SoftwareClassificationInfo> list;


@override
protected void onCreate(Bundle savedInstanceState) {

          super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
            swipeLayout.setOnRefreshListener(this);
            swipeLayout.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);


            list = new ArrayList<SoftwareClassificationInfo>();
            list.add(new SoftwareClassificationInfo(1, "asdas"));


            listView = (ListView) findViewById(R.id.list);
            adapter = new ListViewAdapter(this, list);
            listView.setAdapter(adapter);
}
@override
public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
            public void run() {
                         swipeLayout.setRefreshing(false);
                         list.add(new SoftwareClassificationInfo(2, "ass"));
                         adapter.notifyDataSetChanged();
             }
            }, 1000);
           }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章