主类:CityWeather继承于Activity
它和项目描述配置文件中注册:
<activity android:name=".CityWeather"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
该类实现Activity类的方法
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//界面初始化方法
init();
}
init方法主要是用来初始化应用界面的,具体实现方法:
以上代码中:
/*
* 通过URL获取网络资源
* 由于访问网络,所以要在AndroidManifest.xml中加入访问因特网服务的权限
* <uses-permission android:name="android.permission.INTERNET" />
*/
URL url = new URL(ConstData.queryString + cityParamString);
//获取网络资源信息
getCityWeather(url);
getCityWeather(url)主要是用来获取天气信息的:
一下几个类主要是属于工具辅助类,为我们的主类提供函数调用的
GoogleWeatherHandler:该类为一个handler类,专门用来处理xml文件的。
SingleWeatherInfoView:该类为自定义的一个LinearLayout布局类。对应于布局文件的xml
WeatherCurrentCondition:该类为实时查询的信息情况。
WeatherForecastCondition:未来几天天气信息情况。
WeatherSet:设置当前实时天气信息和未来天气信息。
源码可从我的资源里下载