欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

wenserver獲取天氣預報數據實例分享

 更新時間:2013年12月18日 15:56:11   作者:  
wenserver獲取天氣預報數據,實現android顯示天氣信息

復制代碼 代碼如下:

package tao.cs;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class WeatherMain extends Activity {
    Button btn01;  
    TextView tv01,tv02;  
    ImageView imgview01,imgview02;  
    EditText et01;  

    int int_img_1;  
    int int_img_2;  

     public void onCreate(Bundle savedInstanceState) {  
         super.onCreate(savedInstanceState);  
         setContentView(R.layout.main);  

         //組件  
       //  final EditText et01=(EditText) findViewById(R.id.et_TextWeather);  
         btn01=(Button) findViewById(R.id.Button01);  
         tv01=(TextView) findViewById(R.id.TextView01);  
         tv02=(TextView) findViewById(R.id.TextView02);  
         imgview01=(ImageView) findViewById(R.id.ImageView01);  
         imgview02=(ImageView) findViewById(R.id.ImageView02);  
         et01=(EditText) findViewById(R.id.EditText01);  

         btn01.setOnClickListener(new OnClickListener() {  

             public void onClick(View v) {  
                 showWeather();  

             }  
         });  

           
     }//onCreate ***************end  
     protected void showWeather(){//顯示所有的信息  

         String str_city=et01.getText().toString();  
         if(str_city.length()==0){  
             str_city="重慶";  

         }  
//         str_city="濟南";  
         getWeather(str_city);  
         tv01.setText(getString_WeatherToday());  //今天天氣  
         tv02.setText(getString_WeatherCurrent());//當前天氣  
         imgview01.setImageResource(getIcon_1());  //當前的兩個圖標  
         imgview02.setImageResource(getIcon_2());  

     }//showWeather()*****************end  

     private static final String NAME_SPACE="http://WebXml.com.cn/";//命名空間  ,后期測試一下命名空間的作用  
     private static final String METHOD_NAME = "getWeatherbyCityName";  
     private static String URL = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx";// 投遞SOAP數據的目標地址  
     private static String SOAP_ACTION = "http://WebXml.com.cn/getWeatherbyCityName";  

     protected void getWeather(String strcityname){//str 是城市名  
  /* 
   * 這里要做的工作是 提交客戶端的請求, 
   * 然后獲得服務端返回的復雜對象,后面會有專門的 
   */ 
         SoapObject sobject=new SoapObject(NAME_SPACE, METHOD_NAME);  
         sobject.addProperty("theCityName", strcityname);  

         AndroidHttpTransport ht=new AndroidHttpTransport(URL);  
         ht.debug=true;  

         SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);//告訴SoapSerializationEnvelope把構造好的SoapObject封裝進去:  
         envelope.bodyOut=sobject;  
         envelope.dotNet=true;  
         envelope.setOutputSoapObject(sobject);  

         try {  

             ht.call(SOAP_ACTION, envelope);  

         } catch (IOException e) {  

             e.printStackTrace();  
         } catch (XmlPullParserException e) {  

             e.printStackTrace();  
         }  
         // 
         SoapObject result=(SoapObject) envelope.bodyIn;  
         SoapObject detail=(SoapObject) result.getProperty("getWeatherbyCityNameResult");//類似于獲取服務端返回復雜節(jié)點的一個內接點  
         parseWeather(detail);   

     }//getweather *****************end  

     String str_weather_today=null;  
     String str_weather_current=null;  
     protected void parseWeather(SoapObject so){  
         /* 
          * 解析復雜節(jié)點,并對相應的參數賦值,為后面的方法準備 
          */ 
         //第六個參數是概況,包括日期,天氣....  
         String date=so.getProperty(6).toString();  

         str_weather_today="今天: "+date.split(" ")[0];  
         str_weather_today=str_weather_today+"\n氣溫:"+so.getProperty(5).toString();  
         str_weather_today=str_weather_today+"\n風力:"+so.getProperty(7).toString()+"\n";  
         //兩個圖標  
         int_img_1=parseIcon(so.getProperty(8).toString());  
         int_img_2=parseIcon(so.getProperty(9).toString());  

         str_weather_current=so.getProperty(10).toString();  
     }  
     public String getString_WeatherToday(){  
         return str_weather_today;  
     }  
     public String getString_WeatherCurrent(){  
         return str_weather_current;  
     }  

     public int getIcon_1(){  
         return int_img_1;  
     }  
     public int getIcon_2(){  
         return int_img_2;  
     }  
     public int   parseIcon(String strIcon){  
         if (strIcon == null) return -1;  

         if ("0.gif".equals(strIcon)) return R.drawable.a_0;  
         if ("1.gif".equals(strIcon)) return R.drawable.a_1;  
         if ("2.gif".equals(strIcon)) return R.drawable.a_2;  
         if ("3.gif".equals(strIcon)) return R.drawable.a_3;  
         if ("4.gif".equals(strIcon)) return R.drawable.a_4;  
         if ("5.gif".equals(strIcon)) return R.drawable.a_5;  
         if ("6.gif".equals(strIcon)) return R.drawable.a_6;  
         if ("7.gif".equals(strIcon)) return R.drawable.a_7;  
         if ("8.gif".equals(strIcon)) return R.drawable.a_8;  
         if ("9.gif".equals(strIcon)) return R.drawable.a_9;  
         if ("10.gif".equals(strIcon)) return R.drawable.a_10;  
         if ("11.gif".equals(strIcon)) return R.drawable.a_11;  
         if ("12.gif".equals(strIcon)) return R.drawable.a_12;  
         if ("13.gif".equals(strIcon)) return R.drawable.a_13;  
         if ("14.gif".equals(strIcon)) return R.drawable.a_14;  
         if ("15.gif".equals(strIcon)) return R.drawable.a_15;  
         if ("16.gif".equals(strIcon)) return R.drawable.a_16;  
         if ("17.gif".equals(strIcon)) return R.drawable.a_17;  
         if ("18.gif".equals(strIcon)) return R.drawable.a_18;  
         if ("19.gif".equals(strIcon)) return R.drawable.a_19;  
         if ("20.gif".equals(strIcon)) return R.drawable.a_20;  
         if ("21.gif".equals(strIcon)) return R.drawable.a_21;  
         if ("22.gif".equals(strIcon)) return R.drawable.a_22;  
         if ("23.gif".equals(strIcon)) return R.drawable.a_23;  
         if ("24.gif".equals(strIcon)) return R.drawable.a_24;  
         if ("25.gif".equals(strIcon)) return R.drawable.a_25;  
         if ("26.gif".equals(strIcon)) return R.drawable.a_26;  
         if ("27.gif".equals(strIcon)) return R.drawable.a_27;  
         if ("28.gif".equals(strIcon)) return R.drawable.a_28;  
         if ("29.gif".equals(strIcon)) return R.drawable.a_29;  
         if ("30.gif".equals(strIcon)) return R.drawable.a_30;  
         if ("31.gif".equals(strIcon)) return R.drawable.a_31;  

         return 0;  
     }


}

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<EditText

 android:id="@+id/EditText01"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content">
</EditText>
<Button
 android:text="查詢"
 android:id="@+id/Button01"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
</Button>
<ImageView
 android:id="@+id/ImageView01"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
</ImageView>
<ImageView
 android:id="@+id/ImageView02"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
</ImageView>
<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/TextView01"

    />
<TextView

 android:id="@+id/TextView02"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
</TextView>


</LinearLayout>

相關文章

  • 解決Android屏幕四周閃現紅框的問題

    解決Android屏幕四周閃現紅框的問題

    這篇文章主要介紹了解決Android屏幕四周閃現紅框的問題,需要的朋友可以參考下
    2017-06-06
  • Android App 與 U 盤通信示例詳解

    Android App 與 U 盤通信示例詳解

    本篇文章主要介紹了Android App 與 U 盤通信詳解,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android編程之交互對話框實例淺析

    Android編程之交互對話框實例淺析

    這篇文章主要介紹了Android編程之交互對話框,結合實例形式簡單分析了Android交互對話框AlertDialog的功能、簡單用法及相關注意事項,需要的朋友可以參考下
    2017-03-03
  • flutter監(jiān)聽app進入前后臺狀態(tài)的實現

    flutter監(jiān)聽app進入前后臺狀態(tài)的實現

    在開發(fā)app的過程中,我們經常需要知道app處于前后臺的狀態(tài),本文主要介紹了flutter監(jiān)聽app進入前后臺狀態(tài)的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-04-04
  • android自定義控件和自定義回調函數步驟示例

    android自定義控件和自定義回調函數步驟示例

    這篇文章主要介紹了android自定義控件步驟示例,包括為View類增加屬性、響應用戶消息、自定義回調函數等方法
    2014-01-01
  • Android13?加強Intent?filters?的安全性

    Android13?加強Intent?filters?的安全性

    這篇文章主要介紹了Android13?加強Intent?filters?的安全性,文章基于Android13?展開Intent?filters?安全性加強的詳細介紹,需要的小伙伴可以參考一下
    2022-05-05
  • 修改Android App樣式風格的方法

    修改Android App樣式風格的方法

    本文講的是如何修改Android App樣式風格的方法,具體可以看下面的代碼
    2013-11-11
  • Android 獲取服務器與客戶端時差的實例代碼

    Android 獲取服務器與客戶端時差的實例代碼

    下面小編就為大家分享一篇Android 獲取服務器與客戶端時差的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Kotlin Job啟動流程源碼層深入分析

    Kotlin Job啟動流程源碼層深入分析

    如果要我拿現實中的一事物與Kotlin協(xié)程中的Job做一個類比,那么我會把Job比作成海洋中的冰山。自由漂浮的冰山約有90%體積沉在海水表面下,因此看著浮在水面上的形狀并猜不出水下的形狀
    2022-11-11
  • Android Studio無法打開得問題解決方法

    Android Studio無法打開得問題解決方法

    這篇文章主要詳細介紹了Android Studio無法打開問題解決辦法,文中有詳細的解決步驟和圖文介紹,對我們解決這個問題有一定的幫助,需要的朋友可以參考下
    2023-07-07

最新評論