Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Android 实现省份城市的选择,并获取城市编号

Android 实现省份城市的选择,并获取城市编号。该程序主要使用 中央气象局 省份 城市数据库为基础 进行读取城市数据库下载免费下载地址在 http://linux.linuxidc.com/  (说明:此地址不是FTP,直接点击打开,输入用户名与密码)用户名与密码都是www.linuxidc.com具体下载目录在 /2013年资料/7月/7日/Android 实现省份城市的选择,并获取城市编号本文源码下载下载在Linux公社的1号FTP服务器里,下载地址:FTP地址:ftp://ftp1.linuxidc.com用户名:www.6688.cc密码:www.linuxidc.com在 2013年LinuxIDC.com7月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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cityselection"
    android:versionCode="1"
    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" />
    <!-- sdcard操作允许 -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".City_SelectionActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application></manifest>布局文件main.xml主要使用两个 spinner  分别实现城市 省份的选择<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >    <TextView
        android:text="省份/直辖市"
        android:textSize="20dp"
        android:textStyle="bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      />
    <Spinner
        android:id="@+id/provinces"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      />
    <TextView
        android:text="市/县"
        android:textSize="20dp"
        android:textStyle="bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      />
    <Spinner
        android:id="@+id/city"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        /></LinearLayout>