0

I have this activity:

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());
        } 
    }

}

I have also set up GD Library,but when I change "activity" to "GDActivity" and "setContentView" to "setActionBarContentView" my App ForceCloses. Sorry for my english.

4

1 回答 1

0

您使用的是最新版本的 YWeatherGetter4a 库吗?如果没有,您需要在另一个线程中设置 textview 的文本,例如,使用 AsyncTask 类。

于 2013-05-27T09:01:27.170 回答