我有这个活动:
package zh.wang.android.yweathergetter;
import greendroid.app.GDActivity;
import zh.wang.android.utils.YahooWeather4a.WeatherInfo;
import zh.wang.android.utils.YahooWeather4a.YahooWeatherInfoListener;
import zh.wang.android.utils.YahooWeather4a.YahooWeatherUtils;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements YahooWeatherInfoListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
YahooWeatherUtils yahooWeatherUtils = YahooWeatherUtils.getInstance();
yahooWeatherUtils.queryYahooWeather(getApplicationContext(), "Madrid", this);
}
@Override
public void gotWeatherInfo(WeatherInfo weatherInfo) {
// TODO Auto-generated method stub
if(weatherInfo != null) {
TextView tv = (TextView) findViewById(R.id.textview_weather_info);
tv.setText(weatherInfo.getTitle() + "n"
+ weatherInfo.getLocationCity() + ", "
+ weatherInfo.getLocationCountry() + "n"
+ "Climatología: " + weatherInfo.getCurrentText() + "n"
+ "Temperatura actual: " + weatherInfo.getCurrentTempC() + "ºC"+ "n"
+ "Previsión para mañana: " + weatherInfo.getForecast1Text() + "n"
+ "Previsión para pasado mañana: " + weatherInfo.getForecast2Text());
}
}
}
我还设置了GD库,但是当我将"activity"更改为"GDActivity"one_answers"setContentView"更改为"setActionBarContentView"时,我的App forceclose。对不起,我的英语不好。
您是否使用最新版本的YWeatherGetter4a库?如果没有,你需要在另一个线程中设置textview的文本,例如,使用AsyncTask类。