0
我尝试使用Snackbar,但它需要一个视图,我已将mainlayout定义为View对象。并在Json响应完成时使用。 但我没有看到任何小吃店弹出? 有没有办法处理? 下面是我解析JSON响应时的处理方式。Json响应后如何使用Snackbar?
public CityWeather parseJSONResponse(JSONObject response){
cityWeather=new CityWeather();
Log.d(LOG_TAG,"parse1");
JSONObject resp= response;
JSONObject detailJo;
JSONObject cityJo;
JSONObject aqiJo;
String aqi;
String city;
String nowtemp;
String condcd;
String pm25;
try {
Log.d(LOG_TAG,"start parse");
//Log.d(LOG_TAG,resp.toString());
JSONArray weatherarrary = resp.getJSONArray(KEY_API);
Log.d(LOG_TAG,"start parse2");
//get Details
detailJo=weatherarrary.getJSONObject(0);
Log.d(LOG_TAG,"start parse3");
//getAQI
//Log.d(LOG_TAG,detailJo.toString());
cityJo=detailJo.getJSONObject(KEY_AQI);
Log.d(LOG_TAG,"after send json true");
//when city not found
if (cityJo==null){
Log.d(LOG_TAG,"parse fail");
return cityWeather;
}
aqiJo=cityJo.getJSONObject(KEY_CITY);
Log.d(LOG_TAG,aqiJo.toString());
aqi=aqiJo.getString(KEY_AQI);
pm25=aqiJo.getString(KEY_PM25);
Log.d(LOG_TAG,"parse succss1"+aqi+" "+pm25);
//get City
cityJo=detailJo.getJSONObject(KEY_BASIC);
city=cityJo.getString(KEY_CITY);
Snackbar.make(mainview,city+"添加成功",Snackbar.LENGTH_SHORT);
//get now temp
cityJo=detailJo.getJSONObject(KEY_NOW);
nowtemp=cityJo.getString(KEY_TMP);
Log.d(LOG_TAG,"parse succss2"+city+" "+nowtemp);
//
cityJo=cityJo.getJSONObject(KEY_COND);
condcd=cityJo.getString(KEY_CODE);
Log.d(LOG_TAG,"parse succss3"+condcd);
cityWeather=new CityWeather(city,aqi,pm25,Integer.parseInt(nowtemp),Integer.parseInt(condcd));
}catch (JSONException je){
Log.d(LOG_TAG,"JSONexp"+je.toString());
}
Log.d(LOG_TAG,"parse succss4");
return cityWeather;
}
Snackbar.make(MAINVIEW,城市+ “添加成功”,Snackbar.LENGTH_SHORT).show(); – W0rmH0le
你在Snackbar.make().show();)结尾缺少.show(); – W0rmH0le