最近简单的使用了Android的下拉刷新控件SwipeRefreshLayout
首先是布局
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/id_listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
在activity中使用
private SwipeRefreshLayout mSwipeLayout; //下拉刷新控件
mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly);
mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.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);
刷新回调函数
@Override
public void onRefresh() {
// TODO Auto-generated method stub
//dosomething
mSwipeLayout.setRefreshing(false);
}