public class MainActivity extends ActionBarActivity implements IXListViewListener { private XListView xListView; private String JSON="http://api.fang.anjuke.com/m/android/1.3/shouye/recInfosV3/?city_id=14&lat=40.04652&lng=116.306033&api_key=androidkey&sig=9317e9634b5fbc16078ab07abb6661c5&macid=45cd2478331b184ff0e15f29aaa89e3e&app=a-ajk&_pid=11738&o=PE-TL10-user+4.4.2+HuaweiPE-TL10+CHNC00B260+ota-rel-keys%2Crelease-keys&from=mobile&m=Android-PE-TL10&cv=9.5.1&cid=14&i=864601026706713&v=4.4.2&qtime=20160411091603&pm=b61&uuid=1848c59c-185d-48d9-b0e9-782016041109&_chat_id=0"; int i=1; private List<Rows> lists = new ArrayList<Rows>(); ListAd m; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //控件 xListView = (XListView) findViewById(R.id.xListView); //他们的配置 xListView.setPullLoadEnable(true); xListView.setPullRefreshEnable(true); xListView.setXListViewListener(this); init(); } private void init() { HttpUtils hu = new HttpUtils(); hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() { @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onSuccess(ResponseInfo<String> arg0) { String str = arg0.result; Gson g = new Gson(); MyObj oj = g.fromJson(str, MyObj.class); List<Rows> list = oj.getResult().getRows(); lists = list; m = new ListAd(MainActivity.this, lists); xListView.setAdapter(m); } }); } @Override public void onRefresh() { init(); onLoad(); } private void onLoad() { //停止刷新、加载 xListView.stopRefresh(); xListView.stopLoadMore(); // 设置日期格式 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 获取当前系统时间 String nowTime = df.format(new Date(System.currentTimeMillis())); // 释放时提示正在刷新时的当前时间 xListView.setRefreshTime(nowTime); } @Override public void onLoadMore() { HttpUtils hu = new HttpUtils(); hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() { @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onSuccess(ResponseInfo<String> arg0) { String str = arg0.result; Gson g = new Gson(); MyObj oj = g.fromJson(str, MyObj.class); List<Rows> list = oj.getResult().getRows(); lists.addAll(list); m.notifyDataSetChanged(); } }); onLoad(); } }
时间: 2024-10-11 16:51:52