第一次写博客,好紧张。
进入正题。
//首先,在布局文件需要添加布局
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
//必须包裹住ListView
</android.support.v4.widget.SwipeRefreshLayout>
//Java文件
SwipeRefreshLayout mSwipeLayout=(SwipeRefreshLayout) getActivity().findViewById(R.id.id_swipe_ly);
//绑定对象
mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
//定义它的颜色
//触发下拉事件
mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {//事件列表
new Handler().postDelayed(new Runnable() {//一个计时器
@Override
public void run() {//新的线程
// TODO Auto-generated method stub
Map<String,Object> Maps=new HashMap<String,Object>();
//声明一个Map用于填充数据
Maps.put("Item_1","String_111");
//填充数据Item_1
Maps.put("Item_2","String_222");
//填充数据Item_2
Arr.add(0,Maps);
//填充数据到arr的0索引处,如果不添加将会添加至最后,arr为全局变量,
不知道的同学就Ctrl+F4吧,类型为ArrayList<Map<String,Object>>
Aadp.notifyDataSetChanged();
//刷新adap,类型为SimpleAdapter
mSwipeLayout.setRefreshing(false);
}
}, 6000);//时间6秒
}
});
}