private XListView xv;
private List list;
private String time;
//2秒刷新以及停止刷新
Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) { myBaseAdapter.notifyDataSetChanged(); close(); }
private void close() { //停止刷新 xv.stopRefresh(); xv.setRefreshTime(time); time=gettime(); //停止加载 xv.stopLoadMore(); }
private String gettime() { SimpleDateFormat format=new SimpleDateFormat("hh:mm:ss");
String string = format.format(new Date()); return string; }; };
//为xlistview设置数据
list = new ArrayList<String>();
for(int i=0;i<100;i++){
list.add(""+i);
}
xv=(XListView)findViewById(R.id.xlistView);
myBaseAdapter = new MyBaseAdapter(this,list);
xv.setAdapter(myBaseAdapter);
//下拉刷新
xv.setPullRefreshEnable(true);
//加载更多
xv.setPullLoadEnable(true);
//xlistView上拉加载下拉刷新监听方法
xv.setXListViewListener(new IXListViewListener() {
@Override
public void onRefresh() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
list.add(0,"你好啊!");
handler.sendEmptyMessage(0);
}
}, 2000);
}
@Override
public void onLoadMore() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
for (int i = 100; i < 200; i++) {
list.add(""+i);
handler.sendEmptyMessage(0);
}
}
}, 2000);
}
});
}