httputils及xlistview刷新

来源:互联网 发布:php微信源码下载 编辑:程序博客网 时间:2024/05/16 04:48
public class MainActivity extends Activity implements IXListViewListener {private XListView xListView;private List<Item> list;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);xListView=(XListView) findViewById(R.id.listView);xListView.setPullRefreshEnable(true);    xListView.setPullLoadEnable(true);    xListView.setXListViewListener(this);    getHttp(1);}protected void getHttp(int cid) {//http://apis.juhe.cn/cook/index?key=3503cb5ddd606f6ab42ead52878007b8&cid=1&dtype=xml// TODO Auto-generated method stubString url="http://apis.juhe.cn/cook/index";HttpUtils httpUtils=new HttpUtils();RequestParams params=new RequestParams();    params.addBodyParameter("key","3503cb5ddd606f6ab42ead52878007b8");    params.addBodyParameter("cid", cid+"");    params.addBodyParameter("dtype","xml");    httpUtils.send(HttpMethod.POST, url, params, new RequestCallBack<String>() {@Overridepublic void onFailure(HttpException arg0, String arg1) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "网络连接失败啦", 0).show();}@Overridepublic void onSuccess(ResponseInfo<String> arg0) {// TODO Auto-generated method stubXStream xStream=new XStream();xStream.processAnnotations(Root.class);Root fromXml=(Root) xStream.fromXML(arg0.result);list=fromXml.getResult().getData().getItem();Log.i("Tag", list.toString());Myadapter adapter=new Myadapter(getApplicationContext(), list);xListView.setAdapter(adapter);}});}@Overridepublic void onRefresh() {// TODO Auto-generated method stubgetHttp(1);onLoad();}private void onLoad() {// TODO Auto-generated method stub 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);}@Overridepublic void onLoadMore() {// TODO Auto-generated method stubgetHttp(1);onLoad();}}

0 0
原创粉丝点击