Android get weather forecast, android Weather Forecast

Source: Internet
Author: User

Android get weather forecast, android Weather Forecast

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: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>

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 class MainActivity7 extends Activity implements OnClickListener {private WebView webView; // declare the object of the WebView component @ Ov Erride protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main_activity7); webView = (WebView) findViewById (R. id. webView1); // obtain the WebView component. getSettings (). setJavaScriptEnabled (true); // set that JavaScript can be used in f webView. setWebChromeClient (new WebChromeClient (); // process the JavaScript dialog box webView. setWebViewClient (new WebViewClient (); // process various notifications and requests If you do not use this code, you will use a built-in browser to access the Web page webView. loadUrl ("http://m.weather.com.cn/m/pn12/weather.htm"); // sets the default display of weather forecasts webView. setInitialScale (57*4); // enlarge the webpage content by 4x. Button bj = (Button) findViewById (R. id. bj); // obtain the "Beijing" button bj added to the layout manager. setOnClickListener (this); Button sh = (Button) findViewById (R. id. sh); // obtain the "Shanghai" button added to the layout manager sh. setOnClickListener (this); Button heb = (Button) findViewById (R. id. heb); // obtain the "Harbin" button heb added to the layout manager. se TOnClickListener (this); Button cc = (Button) findViewById (R. id. cc); // obtain the "Changchun" button cc added in the layout manager. setOnClickListener (this); Button sy = (Button) findViewById (R. id. sy); // obtain the "Shenyang" button sy added in the layout manager. setOnClickListener (this); Button gzener (button#findviewbyid(r.id.gz); // obtain the "Guangzhou" Button gz added in the layout manager. setOnClickListener (this) ;}@ Override public void onClick (View view) {switch (view. getId () {case R. id. bj: // click "Beijing" button openUrl ("1010 10100 T "); break; case R. id. sh: // click the "Shanghai" button openUrl ("101020100 T"); break; case R. id. heb: // click the "Harbin" button openUrl ("101050101 T"); break; case R. id. cc: // click the "Changchun" button openUrl ("101060101 T"); break; case R. id. sy: // click the "Shenyang" button openUrl ("101070101 T"); break; case R.id.gz: // click the "Guangzhou" button openUrl ("101280101 T"); break ;}/// method to open the webpage private void openUrl (String id) {webView. loadUrl ("http://m.weather.com.cn/m/pn12/w Eather.htm? Id = "+ id +" "); // obtain and display weather forecast information }}

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

Related Article

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.