protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置隐藏标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//加载xml文件
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.list);
HttpUtils until=new HttpUtils();
until.send(HttpMethod.GET, "http://www.oschina.net/action/api/news_list", new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
//吐司
Toast.makeText(MainActivity.this, "请求数据失败", 1).show();
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.result);
// 创建xstream对象
XStream xstream=new XStream();
//注解的使用方式,使用前必须加上注解类才有作用
xstream.processAnnotations(MySupper.class);
MySupper ms=(MySupper) xstream.fromXML(arg0.result);
List<Mynews> list=ms.getNewslist().getNews();
//为控件添加适配器
Base ba=new Base(MainActivity.this, list);
lv.setAdapter(ba);
}
});
/*//创建异步加载的对象
new MyAsyncTask().execute();*/
}
XUtils解析
浙公网安备 33010602011771号