天气预报——textView显示后再加载数据无法更新,换种方式写

 
使用了聚合数据的sdk开发:
 
private void initForecastByJuhe(){
  Parameters params=new Parameters();

  params.add("cityname","烟台");
  params.add("dtype", "json");

  JuheData.executeWithAPI(getApplicationContext(), 73,
    "http://op.juhe.cn/onebox/weather/query",
    JuheData.GET, params,
    new DataCallBack() {

@Override
public void onSuccess(int arg0, String result) {
// TODO Auto-generated method stub
if (result != null) {
try {
JSONObject jo = new JSONObject(result);
jo = new JSONObject(jo.getString("result"));
jo = new JSONObject(jo.getString("data"));
JSONObject jrealtime = new JSONObject(jo
.getString("realtime"));

f.setCity_name(jrealtime.getString("city_name"));
f.setMoon_date(jrealtime.getString("moon"));
JSONObject joweather = new JSONObject(jrealtime
.getString("weather"));
f.setTem("温度:"
+ joweather.getString("temperature"));
f.setHum("湿度:"
+ joweather.getString("humidity"));
f.setInfo(joweather.getString("info"));
JSONObject jowind = new JSONObject(jrealtime
.getString("wind"));
f.setWind(jowind.getString("direct") + " "
+ jowind.getString("power"));
JSONObject jolife = new JSONObject(jo
.getString("life"));
JSONObject joLifeInfo = new JSONObject(jolife
.getString("info"));
JSONArray ja = new JSONArray(joLifeInfo
.getString("wuran"));
f.setWuran(ja.get(0) + "," + ja.get(1));
JSONArray janextWeather = new JSONArray(jo
.getString("weather"));
JSONObject jonext = janextWeather
.getJSONObject(1);
jonext = new JSONObject(jonext
.getString("info"));
janextWeather = new JSONArray(jonext
.getString("day"));
f.setNextInfo("明日天气 温度:" + janextWeather.get(2)
+ " " + janextWeather.get(1));
f.setNextWind(janextWeather.get(3) + " "
+ janextWeather.get(4));
String forecast[] = { f.getCity_name(),f.getTem(),
f.getHum(),f.getMoon_date(),f.getInfo(),
f.getWind(),f.getWuran(),f.getNextInfo(),f.getNextWind()};
for (int i = 0; i < forecast.length; i++) {
ResideMenuItem itemf = new ResideMenuItem(getApplicationContext(),0, forecast[i]);
resideMenu.addMenuItem(itemf, ResideMenu.DIRECTION_RIGHT);
}

Toast.makeText(getApplicationContext(),
f.getMoon_date(), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@Override
public void onFinish() {

}

@Override
public void onFailure(int arg0, String arg1, Throwable arg2) {
Toast.makeText(getApplicationContext(),
"错误:"+arg1, Toast.LENGTH_SHORT).show();
}
});
}
原文地址:https://www.cnblogs.com/fanerblog/p/4891743.html