界面布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
> <Button
android:id="@+id/bj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bj" /> <Button
android:id="@+id/sh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sh" /> <Button
android:id="@+id/heb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heb" /> <Button
android:id="@+id/cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cc" /> <Button
android:id="@+id/sy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sy" /> <Button
android:id="@+id/gz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gz" /> </LinearLayout>
<WebView android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:focusable="false"
android:layout_weight="1"
/> </LinearLayout>

后台代码

package com.basillee.asus.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button; public class MainActivity7 extends Activity implements OnClickListener {
private WebView webView; //声明WebView组件的对象 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity7);
webView=(WebView)findViewById(R.id.webView1); //获取WebView组件
webView.getSettings().setJavaScriptEnabled(true); //设置JavaScript可用f
webView.setWebChromeClient(new WebChromeClient()); //处理JavaScript对话框
webView.setWebViewClient(new WebViewClient()); //处理各种通知和请求事件,如果不使用该句代码,将使用内置浏览器访问网页
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm "); //设置默认显示的天气预报信息
webView.setInitialScale(*); //放网页内容放大4倍
Button bj=(Button)findViewById(R.id.bj); //获取布局管理器中添加的“北京”按钮
bj.setOnClickListener(this);
Button sh=(Button)findViewById(R.id.sh); //获取布局管理器中添加的“上海”按钮
sh.setOnClickListener(this);
Button heb=(Button)findViewById(R.id.heb); //获取布局管理器中添加的“哈尔滨”按钮
heb.setOnClickListener(this);
Button cc=(Button)findViewById(R.id.cc); //获取布局管理器中添加的“长春”按钮
cc.setOnClickListener(this);
Button sy=(Button)findViewById(R.id.sy); //获取布局管理器中添加的“沈阳”按钮
sy.setOnClickListener(this);
Button gz=(Button)findViewById(R.id.gz); //获取布局管理器中添加的“广州”按钮
gz.setOnClickListener(this);
}
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.bj: //单击的是“北京”按钮
openUrl("101010100T");
break;
case R.id.sh: //单击的是“上海”按钮
openUrl("101020100T");
break;
case R.id.heb: //单击的是“哈尔滨”按钮
openUrl("101050101T");
break;
case R.id.cc: //单击的是“长春”按钮
openUrl("101060101T");
break;
case R.id.sy: //单击的是“沈阳”按钮
openUrl("101070101T");
break;
case R.id.gz: //单击的是“广州”按钮
openUrl("101280101T");
break;
}
}
//打开网页的方法
private void openUrl(String id){
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm?id="+id+" "); //获取并显示天气预报信息
}
}

更多信息: http://jingyan.baidu.com/season/48891

Android 获取天气预报的更多相关文章

  1. 基于android的天气预报的设计与实现

    目录 应用开发技术及开发平台介绍 应用需求分析 应用功能设计及其描述 应用UI展示 ①开发技术: 本系统是采用面向对象的软件开发方法,基于Android studio开发平台,以Android作为本系 ...

  2. [Android] 免费天气预报接口

    [Android] 免费天气预报接口 这是 国家气象局提供的天气预报接口 [免费] 当然,网上有很多的收费API或者每天定次数的接口 使用 国家气象局 的步骤如下: 1.首先获取城市ID号 北京:10 ...

  3. Android获取内置sdcard跟外置sdcard路径

    Android获取内置sdcard跟外置sdcard路径.(测试过两个手机,亲测可用) 1.先得到外置sdcard路径,这个接口是系统提供的标准接口. 2.得到上一级文件夹目录 3.得到该目录的所有文 ...

  4. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  5. Android获取屏幕宽和高

    android获取屏幕的高度和宽度用到WindowManager这个类,两种方法:   1.WindowManager wm = (WindowManager) getContext()        ...

  6. android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位

    android 获取文件夹.文件的大小 以B.KB.MB.GB 为单位   public class FileSizeUtil { public static final int SIZETYPE_B ...

  7. Android获取APK包名的几种方法

    Android获取APK包名的几种方法:1.adb shell pm list package -f | findstr 关键字 #只能获取到包名,主Activity名无法获取到 2.使用aapt-- ...

  8. [整]C#获取天气预报信息(baidu api)包括pm2.5

    /// <summary> /// 获取天气预报信息 /// </summary> /// <returns></returns> public Bai ...

  9. I.MX6 android 获取framebuffer信息

    /******************************************************************************** * I.MX6 android 获取 ...

随机推荐

  1. TcxVerticalGrid demo

    procedure TForm1.Button1Click(Sender: TObject);var row: TcxEditorRow; i,t: Integer;begin grid.ClearR ...

  2. [Objective-c 基础 - 1.2] OC的基本类

    #import <Foundation/Foundation.h> typedef enum {GenderMan, GenderFemale} Gender; typedef enum ...

  3. 如何自己动手实现 KVO(转)

    KVO (Key-Value Observing) KVO 是 Objective-C 对观察者模式(Observer Pattern)的实现.也是 Cocoa Binding 的基础.当被观察对象的 ...

  4. 如何使用IAR仿真环境查看CPU类型字长?

    在此操作之前假设已有一个现成的cpu代码工程如:IAR for Stm8的Demo工程. 点软件仿真进入调试状态 单击菜单栏View –> Watch –> Watch 在新弹出来的Wat ...

  5. C# 创建、安装和卸载Windows服务程序

    1.新建一个windows服务程序. 2.点击这个服务类,从工具箱中加入一个Timer控件,右键这个Timer控件 命名为 timerOrderDeductionDetailJob,Enable设为T ...

  6. WaterWave

    WaterWave.rar

  7. C_数据结构_链表的链式实现

    传统的链表不能实现数据和链表的分离,一旦数据改变则链表就不能用了,就要重新开发. 如上说示:外层是Teacher,里面小的是node. #ifndef _MYLINKLIST_H_ #define _ ...

  8. LayoutInflater

    Android中LayoutInflater的使用 博客分类: Android   Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater的作用类似于 f ...

  9. 不同linux系统添加开机启动程序的命令

    see http://phpcj.org/blog/%E4%B8%8D%E5%90%8Clinux%E7%B3%BB%E7%BB%9F%E6%B7%BB%E5%8A%A0%E5%BC%80%E6%9C ...

  10. JPA OpenJPA 简单例子

    JPA 全称,Java Persistence API,Java持久化API JPA是一套持久化标准,相当于JDBC标准,针对于此标准的实现目前有OpenJAP,TOPLINK,Hibernate等. ...