package com.example.day05_xlistview_;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import com.example.day05_xlistview_.XListView.IXListViewListener;
public class MainActivity extends Activity {
/* String[] arr = new String[] { "1", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "12", "13", "14", "15", "17", "189", "11",
"1", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
"12", "13", "14", "15", "17", "189", "11",
};*/
private List<String> list;
private MyBaseAdapter myBaseAdapter;
private XListView xlistView;
String time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setData();
xlistView = (XListView) findViewById(R.id.xlistView);
//激活上拉加载更多
xlistView.setPullLoadEnable(true);
myBaseAdapter = new MyBaseAdapter(this,list);
xlistView.setAdapter(myBaseAdapter);
//xlistView上拉加载下拉刷新监听方法
xlistView.setXListViewListener(new IXListViewListener() {
@Override//下拉刷新监听方法
public void onRefresh() {
//1.联网请求数据
//2.解析数据
//清除之前的数据,添加
list.clear();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
//通知适配器刷新数据
myBaseAdapter.notifyDataSetChanged();
//停止xlistView下拉刷新
xlistView.stopRefresh();
//设置上次刷新时间
xlistView.setRefreshTime(time);
//记录当前刷新时间
time=getTime();
}
@Override//上拉加载更多监听方法
public void onLoadMore() {
list.add("A");
list.add("B");
list.add("C");
list.add("D");
//通知适配器刷新数据
myBaseAdapter.notifyDataSetChanged();
//停止xlistView加载更多
xlistView.stopLoadMore();
}
});
}
private void setData() {
list = new ArrayList<String>();
for(int i=0;i<100;i++){
list.add(""+i);
}
}
private String getTime(){
SimpleDateFormat format=new SimpleDateFormat("hh:mm:ss");
String string = format.format(new Date());
return string;
}
}