http://www.eoeandroid.com/thread-328133-1-1.html
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);
}
}
Demo如下,感谢大家支持。