使用weather.com.cn数据实现的简易天气demo

通过网上搜索,找到了中国中央气象局的天气接口网址:http://m.weather.com.cn/data/101010100.html,其中数字部分为城市代码。从网上找到一个sqlite的数据库,存储了省市区的信息和城市代码,一共2556条数据,程序先将数据库copy到程序目录的file下,再读取。连网部分是使用AsyncHttpClient写的。

基本想法是做两个界面,一个界面用于显示从接口返回的数据,一个界面用于选择城市。为了简便,直接将json数据放在textview中显示,不再解析。

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="jsj.lgl.weather.MainActivity" >

    <Button
        android:id="@+id/btn_setting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="select area" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/btn_setting" >

        <TextView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/btn_setting" />
    </ScrollView>

</RelativeLayout>


MainActivity.java

package jsj.lgl.weather;

import java.io.UnsupportedEncodingException;

import org.apache.http.Header;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.FastjsonHttpResponseHandler;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值