我尝试使用Snackbar,但它需要一个视图,我已将mainlayout定义为View对象。并在Json响应完成时使用。 但我没有看到任何小吃棒弹出窗口? 有办法处理吗? 下面是解析JSON响应时的处理方式。
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;
}
答案 0 :(得分:0)
您没有通过Snackbar
show()
检查更改后是否仍有问题:
Snackbar.make(mainview,city+"添加成功",Snackbar.LENGTH_SHORT);
要:
Snackbar.make(mainview,city+"添加成功",Snackbar.LENGTH_SHORT).show();