当本人传入特定值,页面可以显示。
for (int i = 0; i < 20; i++) { HashMap<String, String> map = new HashMap<String, String>(); map.put("carbrand", "奥迪A4"); map.put("models", "14款 40 TFSl allroad quattro lius"); map.put("mark_price", "46.98万"); map.put("price", "36.17万"); map.put("user", "经销商名字"); map.put("province", "湖南"); map.put("area", "开福区"); data_car.add(map); }
换成Json后,就显示不出来了,但是本人数据都获取到了。另外一个fragment一模一样的写法都可以正常显示,这个fragment无论怎么样都加载不出来!
x.http().post(requestParams, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { LogOut(result,TAG); try { JSONObject jsonObject = new JSONObject(result); int code = jsonObject.getInt("code"); if (code == 1) { CommTools.showToast(jsonObject.getString("success")); // jsonObject= jsonObject.getJSONObject("data"); JSONArray jsonArray = jsonObject.getJSONArray("data"); for (int i = 0; i < jsonArray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject item = jsonArray.getJSONObject(i); String carbrand = item.getString("carbrand"); String models = item.getString("models"); String mark_price = item.getString("mark_price"); String price = item.getString("price"); String area = item.getString("area"); String province = item.getString("province"); String user = item.getString("user"); map.put("carbrand",carbrand); map.put("models",models); map.put("mark_price",mark_price); map.put("price",price); map.put("area",area); map.put("province",province); map.put("user",user); data_car.add(map); } }else { CommTools.showToast(jsonObject.getString("success")); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } }); SimpleAdapter simple_car = new SimpleAdapter(App.getInstance(), data_car, R.layout.item_car, new String[]{"carbrand","models","mark_price","price","user","province","area"}, new int[]{R.id.tv_carbrand, R.id.tv_carintro, R.id.tv_carzhidao, R.id.tv_carprice, R.id.tv_jsxname,R.id.tv_jsxlocal,R.id.tv_jxsarea}); carListView.setAdapter(simple_car);
一直解不出来,本人真的毫无头绪!
解决方案
20
晕了,x.http().post() 是异步方法吧,还没等data_car有数据,你就setAdapter了,怎么会显示出来啊,假如你的onSuccess方法是是在主线程执行的话就把这段代码放到 onSuccess的获取数据代码的后面。
SimpleAdapter simple_car = new SimpleAdapter(App.getInstance(), data_car, R.layout.item_car, new String[]{"carbrand","models","mark_price","price","user","province","area"}, new int[]{R.id.tv_carbrand, R.id.tv_carintro, R.id.tv_carzhidao, R.id.tv_carprice, R.id.tv_jsxname,R.id.tv_jsxlocal,R.id.tv_jxsarea}); carListView.setAdapter(simple_car);