Android Get weather Forecast

Source: Internet
Author: User

Interface layout

<?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:la Yout_width= "Wrap_content" android:layout_height= "wrap_content" > <button android:id= "@+id/bj" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Androi             d:text= "@string/bj"/> <button android:id= "@+id/sh" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "@string/sh"/> <button A            Ndroid:id= "@+id/heb" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "@string/heb"/&GT <button android:id= "@+id/cc" android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:text= "@string/cc"/> <button android:id= "@+id/sy" an Droid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/sy"/&G        T <button android:id= "@+id/gz" android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:text= "@string/gz"/> </LinearLayout> <webview android:id= "@+id/webvie        W1 "android:layout_width=" Wrap_content "android:layout_height=" 0dip "android:focusable=" false " android:layout_weight= "1"/></linearlayout>

Background code

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 classMainActivity7 extends Activity implements Onclicklistener {PrivateWebView WebView;//declaring an object of the WebView component@Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY7); WebView= (WebView) Findviewbyid (R.ID.WEBVIEW1);//Get WebView ComponentsWebview.getsettings (). setjavascriptenabled (true);//set JavaScript available fWebview.setwebchromeclient (NewWebchromeclient ());//working with JavaScript dialog boxesWebview.setwebviewclient (NewWebviewclient ());//handles various notification and request events, and if you do not use this code, you will use the built-in browser to access the Web pageWebview.loadurl ("http://m.weather.com.cn/m/pn12/weather.htm");//set weather forecast information to be displayed by defaultWebview.setinitialscale ( $*4);//Enlarge 4 times times the content of the pageButton bj= (button) Findviewbyid (R.ID.BJ);//get the "Beijing" button added in the Layout managerBj.setonclicklistener ( This); Button SH= (Button) Findviewbyid (r.id.sh);//get the "Shanghai" button added in the Layout managerSh.setonclicklistener ( This); Button heb= (Button) Findviewbyid (R.id.heb);//get the "Harbin" button added in the Layout managerHeb.setonclicklistener ( This); Button cc= (Button) Findviewbyid (r.id.cc);//get the "Changchun" button added in the Layout managerCc.setonclicklistener ( This); Button Sy= (Button) Findviewbyid (r.id.sy);//get the "Shenyang" button added in the Layout managerSy.setonclicklistener ( This); Button GZ= (Button) Findviewbyid (r.id.gz);//get the "Guangzhou" button added in the Layout managerGz.setonclicklistener ( This); } @Override Public voidOnClick (view view) {Switch(View.getid ()) { CaseR.ID.BJ://Click on the "Beijing" buttonOPENURL ("101010100T");  Break;  CaseR.id.sh://Click on the "Shanghai" buttonOPENURL ("101020100T");  Break;  CaseR.id.heb://Click on the "Harbin" buttonOPENURL ("101050101T");  Break;  Caser.id.cc://Click on the "Changchun" buttonOPENURL ("101060101T");  Break;  CaseR.id.sy://Click on the "Shenyang" buttonOPENURL ("101070101T");  Break;  CaseR.id.gz://Click on the "Guangzhou" buttonOPENURL ("101280101T");  Break; }    }    //ways to open a Web page    Private voidOPENURL (String id) {Webview.loadurl ("http://m.weather.com.cn/m/pn12/weather.htm?id="+id+" ");//Get and display weather forecast information    }}

More information: http://jingyan.baidu.com/season/48891

Android Get weather Forecast

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.