该程序主要使用 中央气象局 省份 城市数据库为基础 进行读取
城市数据库下载
具体下载目录在 /2013年资料/7月/7日/Android 实现省份城市的选择,并获取城市编号
本文源码下载
下载在Linux公社的1号FTP服务器里,下载地址:
用户名:www.6688.cc
在 2013年LinuxIDC.com\7月\Android 实现省份城市的选择,并获取城市编号
下载方法见 http://www.linuxidc.net/thread-1187-1-1.html
-------------------------------------分割线-------------------------------------
下载的数据库 db_weather.db 放到sdcard/weather 目录下面 方便后续操作
为了更好的了解数据库,使用 SQLite Database Browser 可以打开数据库 查看数据 和表等信息,如下



了解了表的构成可以实现操作了
androidManifest.xml
配置文件声明 添加操作sdcard 权限
< xml version="1.0" encoding="utf-8" >
package="com.cityselection"
android:versionCode="1"
android:versionName="1.0" >
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:name=".City_SelectionActivity"
android:label="@string/app_name" >
布局文件main.xml
主要使用两个 spinner 分别实现城市 省份的选择
< xml version="1.0" encoding="utf-8" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:text="省份/直辖市"
android:textSize="20dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:id="@+id/provinces"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:text="市/县"
android:textSize="20dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:id="@+id/city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>