Android 获取天气预报
界面布局
<?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 获取天气预报的更多相关文章
- 基于android的天气预报的设计与实现
目录 应用开发技术及开发平台介绍 应用需求分析 应用功能设计及其描述 应用UI展示 ①开发技术: 本系统是采用面向对象的软件开发方法,基于Android studio开发平台,以Android作为本系 ...
- [Android] 免费天气预报接口
[Android] 免费天气预报接口 这是 国家气象局提供的天气预报接口 [免费] 当然,网上有很多的收费API或者每天定次数的接口 使用 国家气象局 的步骤如下: 1.首先获取城市ID号 北京:10 ...
- Android获取内置sdcard跟外置sdcard路径
Android获取内置sdcard跟外置sdcard路径.(测试过两个手机,亲测可用) 1.先得到外置sdcard路径,这个接口是系统提供的标准接口. 2.得到上一级文件夹目录 3.得到该目录的所有文 ...
- Android获取系统时间方法的总结
Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...
- Android获取屏幕宽和高
android获取屏幕的高度和宽度用到WindowManager这个类,两种方法: 1.WindowManager wm = (WindowManager) getContext() ...
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
android 获取文件夹.文件的大小 以B.KB.MB.GB 为单位 public class FileSizeUtil { public static final int SIZETYPE_B ...
- Android获取APK包名的几种方法
Android获取APK包名的几种方法:1.adb shell pm list package -f | findstr 关键字 #只能获取到包名,主Activity名无法获取到 2.使用aapt-- ...
- [整]C#获取天气预报信息(baidu api)包括pm2.5
/// <summary> /// 获取天气预报信息 /// </summary> /// <returns></returns> public Bai ...
- I.MX6 android 获取framebuffer信息
/******************************************************************************** * I.MX6 android 获取 ...
随机推荐
- [OC Foundation框架 - 1] 常用结构体
底层封装是使用了typedef定义的结构体 typedef struct _NSString{ xxx xxx } NSString; 1. NSRange 结构体 #注意结构体不是对象 3种定义 ...
- 【PAT Advanced Level】1004. Counting Leaves (30)
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...
- Android 图片加载[常见开源项目汇总]
该文主要是讲一下目前有哪些使用比较多的 图片加载开源项目,并简单介绍该如果使用 以及各开源项目之间有什么区别, 我们该如何去选择适合的开源项目应用到我们的项目中? 一.Android-Universa ...
- http://www.360doc.com/content/10/1012/09/3722251_60285817.shtml
http://www.360doc.com/content/10/1012/09/3722251_60285817.shtml http://www.docin.com/p-163063250.htm ...
- memset函数具体说明
1.void *memset(void *s,int c,size_t n)总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c. 2.样例#include void main(){char ...
- 【《Objective-C基础教程 》笔记ch05】(六)OC中的复合机制Composition
1.复合通过包括作为实例变量的的对象指针实现的. @interface Unicycle : NSObject { Pedal*pedal; ...
- RotatingDoughnut
RotatingDoughnut.zip
- android学习日记03--常用控件ListView
常用控件 8.ListView 列表视图,比如游戏的排行榜.列表数据可以根据屏幕大小自适应 列表的显示需要三个元素: a.ListVeiw:用来展示列表的View. b.适配器:用来把数据映射到Lis ...
- HDU 3157 Crazy Circuits(有源汇上下界最小流)
HDU 3157 Crazy Circuits 题目链接 题意:一个电路板,上面有N个接线柱(标号1~N),还有两个电源接线柱 + -.给出一些线路,每一个线路有一个下限值求一个能够让全部部件正常工作 ...
- JQuery Mobile navbar动态刷新创建
今天突然用到须要动态改变tab页, 布局代码例如以下: <div data-role="navbar" id='divtab'> <ul id='divtabul ...