package com.example.myxlistview;
import java.util.ArrayList;
import me.maxwin.view.XListView;
import me.maxwin.view.XListView.IXListViewListener;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class MainActivity extends Activity implements IXListViewListener{
private XListView listView;
private ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (XListView) findViewById(R.id.lv_pulllv);
listView.setPullLoadEnable(true);
listView.setXListViewListener(this);
loadData();
mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, dataList);
listView.setAdapter(mAdapter);
}
@Override
public void onRefresh() {
index = 0;
dataList.clear();
loadData();
onLoad();
mAdapter.notifyDataSetChanged();
}
//停止刷新
private void onLoad() {
listView.stopRefresh();
listView.stopLoadMore();
listView.setRefreshTime("刚刚");
}
@Override
public void onLoadMore() {
index = index + time_count;
loadData();
onLoad();
mAdapter.notifyDataSetChanged();
}
int index = 0;
int time_count = 20;
ArrayList<String> dataList = new ArrayList<String>();
//模拟加载数据
public void loadData() {
for (int i = index; i < index + time_count; i++) {
dataList.add("我是第" + i + "个条目");
}
}
}