网络请求的数据能用GSON解析出来,但是不能被赋值到listpublicArrayListlist=newArrayList()publicclassAsyncHttpCity{publicstaticArrayListli...
网络请求的数据能用GSON解析出来,但是不能被赋值到list
public ArrayList list=new ArrayList()
public class AsyncHttpCity {
public static ArrayList list=new ArrayList();
/**
* 1.应该不用额外写一个登录的方法,因为本界面是通过主界面跳转过来的,而主界面已经通过了登录
* 2.但是当登录过期的时候可能需要从新认证登录···不知道是否要重新写
*/
public AsyncHttpCity(ArrayList list){
super();
if(list!=null){
this.list=list;
}
else {
this.list=new ArrayList();
}
}
public ArrayList asynchttpcityPost(String city) {
AsyncHttpClient client = new AsyncHttpClient();
// url="";
String url = "";
RequestParams params = new RequestParams();
params.put("user_id", "1");
params.put("md5_code", "facdd148a7d4c75ebdcb60b0716bc590");
params.put("city", city);
client.post(url, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String arg0) {
System.out.println("===AsyncHttpCity=====里面里面里面");
super.onSuccess(arg0);
Gson gson = new Gson();
CityList citylist = gson.fromJson(arg0, CityList.class);
for (int i = 0; i < citylist.content.size(); i++) {
String name=citylist.getContent().get(i).getCityName();
CityEntity cityEntity=new CityEntity();
cityEntity.setName(name);
list.add(0,cityEntity);
Log.i("城市里面的列表", "ist.size()=="+list.size());
}
}
@Override
public void onFailure(Throwable arg0) {
Log.i("错误信息", "网络请求失败:" + arg0);
super.onFailure(arg0);
}
});
Log.i("list.size()", "list.size() of AsyncHttpCity==="+list.size());
return list;
}
}
展开