編輯:關於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");//類似於獲取服務端返回復雜節點的一個內接點
parseWeather(detail);
}//getweather *****************end
String str_weather_today=null;
String str_weather_current=null;
protected void parseWeather(SoapObject so){
/*
* 解析復雜節點,並對相應的參數賦值,為後面的方法准備
*/
//第六個參數是概況,包括日期,天氣....
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 中解決滑動的方案有2種:外部攔截法 和內部攔截法。滑動沖突也存在2種場景: 橫豎滑動沖突、同向滑動沖突。所以我就寫了4個例子來學習如何解決滑動沖突
獲取數據用GET請求 ??增刪改查修改數據用POST請求 package com.example.jreduch07;import android.
MediaPlayer通過如下兩個靜態方法來加載指定的音頻: 1、static MediaPlayer create(Context context,Uri uri
我們要理解Android的消息系統,Looper,Handle,View等概念還是需要從消息系統的基本原理及其構造這個源頭開始。從這個源頭,我們才能很清楚的看到Andro