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