亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1349 | 回復(fù): 0
打印 上一主題 下一主題

[Android] Android獲取天氣預(yù)報(bào) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-05-28 11:01 |只看該作者 |倒序?yàn)g覽
界面布局
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:gravity="center_horizontal"
  5.     android:layout_width="fill_parent"
  6.     android:layout_height="fill_parent"
  7.     >
  8.     <LinearLayout
  9.         android:orientation="horizontal"
  10.         android:layout_width="wrap_content"
  11.         android:layout_height="wrap_content"
  12.         >
  13.   
  14.         <Button
  15.             android:id="@+id/bj"
  16.             android:layout_width="wrap_content"
  17.             android:layout_height="wrap_content"
  18.             android:text="@string/bj" />
  19.   
  20.         <Button
  21.             android:id="@+id/sh"
  22.             android:layout_width="wrap_content"
  23.             android:layout_height="wrap_content"
  24.             android:text="@string/sh" />
  25.   
  26.         <Button
  27.             android:id="@+id/heb"
  28.             android:layout_width="wrap_content"
  29.             android:layout_height="wrap_content"
  30.             android:text="@string/heb" />
  31.   
  32.         <Button
  33.             android:id="@+id/cc"
  34.             android:layout_width="wrap_content"
  35.             android:layout_height="wrap_content"
  36.             android:text="@string/cc" />
  37.   
  38.         <Button
  39.             android:id="@+id/sy"
  40.             android:layout_width="wrap_content"
  41.             android:layout_height="wrap_content"
  42.             android:text="@string/sy" />
  43.   
  44.         <Button
  45.             android:id="@+id/gz"
  46.             android:layout_width="wrap_content"
  47.             android:layout_height="wrap_content"
  48.             android:text="@string/gz" />
  49.   
  50.     </LinearLayout>
  51.     <WebView android:id="@+id/webView1"
  52.         android:layout_width="wrap_content"
  53.         android:layout_height="0dip"
  54.         android:focusable="false"
  55.         android:layout_weight="1"
  56.         />
  57.   
  58. </LinearLayout>
復(fù)制代碼
后臺代碼
  1. package com.basillee.asus.demo;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.webkit.WebChromeClient;
  7. import android.webkit.WebView;
  8. import android.webkit.WebViewClient;
  9. import android.widget.Button;

  10. public class MainActivity7 extends Activity implements OnClickListener {
  11.     private WebView webView;    //聲明WebView組件的對象

  12.     @Override
  13.     protected void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.activity_main_activity7);
  16.         webView=(WebView)findViewById(R.id.webView1);    //獲取WebView組件
  17.         webView.getSettings().setJavaScriptEnabled(true);    //設(shè)置JavaScript可用f
  18.         webView.setWebChromeClient(new WebChromeClient());    //處理JavaScript對話框
  19.         webView.setWebViewClient(new WebViewClient());    //處理各種通知和請求事件,如果不使用該句代碼,將使用內(nèi)置瀏覽器訪問網(wǎng)頁
  20.         webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm ");    //設(shè)置默認(rèn)顯示的天氣預(yù)報(bào)信息
  21.         webView.setInitialScale(57*4);    //放網(wǎng)頁內(nèi)容放大4倍
  22.         Button bj=(Button)findViewById(R.id.bj);        //獲取布局管理器中添加的“北京”按鈕
  23.         bj.setOnClickListener(this);
  24.         Button sh=(Button)findViewById(R.id.sh);        //獲取布局管理器中添加的“上!卑粹o
  25.         sh.setOnClickListener(this);
  26.         Button heb=(Button)findViewById(R.id.heb);        //獲取布局管理器中添加的“哈爾濱”按鈕
  27.         heb.setOnClickListener(this);
  28.         Button cc=(Button)findViewById(R.id.cc);        //獲取布局管理器中添加的“長春”按鈕
  29.         cc.setOnClickListener(this);
  30.         Button sy=(Button)findViewById(R.id.sy);        //獲取布局管理器中添加的“沈陽”按鈕
  31.         sy.setOnClickListener(this);
  32.         Button gz=(Button)findViewById(R.id.gz);        //獲取布局管理器中添加的“廣州”按鈕
  33.         gz.setOnClickListener(this);
  34.     }
  35.     @Override
  36.     public void onClick(View view){
  37.         switch(view.getId()){
  38.             case R.id.bj:        //單擊的是“北京”按鈕
  39.                 openUrl("101010100T");
  40.                 break;
  41.             case R.id.sh:        //單擊的是“上!卑粹o
  42.                 openUrl("101020100T");
  43.                 break;
  44.             case R.id.heb:        //單擊的是“哈爾濱”按鈕
  45.                 openUrl("101050101T");
  46.                 break;
  47.             case R.id.cc:        //單擊的是“長春”按鈕
  48.                 openUrl("101060101T");
  49.                 break;
  50.             case R.id.sy:        //單擊的是“沈陽”按鈕
  51.                 openUrl("101070101T");
  52.                 break;
  53.             case R.id.gz:        //單擊的是“廣州”按鈕
  54.                 openUrl("101280101T");
  55.                 break;
  56.         }
  57.     }
  58.     //打開網(wǎng)頁的方法
  59.     private void openUrl(String id){
  60.         webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm?id="+id+" ");    //獲取并顯示天氣預(yù)報(bào)信息
  61.     }
  62. }
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP