问题描述
packagecom.bzu.weatherforecast;importorg.ksoap2.serialization.SoapObject;importandroid.app.Activity;importandroid.content.ContentValues;importandroid.os.Bundle;importandroid.view.Menu;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.ImageView;importcom.bzu.weatherforecast.tools.WeatherStateSearch;publicclassMainActivityextendsActivity{privateEditTextcity;privateButtonsearch;privateEditTextweastate;privateImageViewimg;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//查找组件city=(EditText)this.findViewById(R.id.city);search=(Button)this.findViewById(R.id.search);weastate=(EditText)this.findViewById(R.id.state);img=(ImageView)this.findViewById(R.id.image);search.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv){Stringcname=city.getText().toString();//web服务端天气预报urlStringwsdlUrl="http://www.webxml.com.cn/webservices/weatherwebservice.asmx";//调用web提供的方法SoapObjectweather=WeatherStateSearch.searchWea(wsdlUrl,"getWeatherbyCityName",cname);Stringstate=weather.getProperty(10).toString();System.out.println(state);StringstrIcon=weather.getProperty(15).toString();//查询结果显示在结果文本域weastate.setText(state);img.setImageResource(parseIcon(strIcon));}});}//查到的图片转换为项目中对应的int类型值privateintparseIcon(StringstrIcon){if("0.gif".equals(strIcon))returnR.drawable.a_0;if("1.gif".equals(strIcon))returnR.drawable.a_1;if("3.gif".equals(strIcon))returnR.drawable.a_3;if("4.gif".equals(strIcon))returnR.drawable.a_4;if("5.gif".equals(strIcon))returnR.drawable.a_5;if("6.gif".equals(strIcon))returnR.drawable.a_6;if("7.gif".equals(strIcon))returnR.drawable.a_7;if("8.gif".equals(strIcon))returnR.drawable.a_8;if("9.gif".equals(strIcon))returnR.drawable.a_9;if("10.gif".equals(strIcon))returnR.drawable.a_10;if("11.gif".equals(strIcon))returnR.drawable.a_11;if("12.gif".equals(strIcon))returnR.drawable.a_12;if("13.gif".equals(strIcon))returnR.drawable.a_13;if("14.gif".equals(strIcon))returnR.drawable.a_14;if("15.gif".equals(strIcon))returnR.drawable.a_15;if("16.gif".equals(strIcon))returnR.drawable.a_16;if("17.gif".equals(strIcon))returnR.drawable.a_17;if("18.gif".equals(strIcon))returnR.drawable.a_18;if("19.gif".equals(strIcon))returnR.drawable.a_19;if("20.gif".equals(strIcon))returnR.drawable.a_20;if("21.gif".equals(strIcon))returnR.drawable.a_21;if("22.gif".equals(strIcon))returnR.drawable.a_22;if("23.gif".equals(strIcon))returnR.drawable.a_23;if("24.gif".equals(strIcon))returnR.drawable.a_24;if("25.gif".equals(strIcon))returnR.drawable.a_25;if("26.gif".equals(strIcon))returnR.drawable.a_26;if("27.gif".equals(strIcon))returnR.drawable.a_27;if("28.gif".equals(strIcon))returnR.drawable.a_28;if("29.gif".equals(strIcon))returnR.drawable.a_29;if("30.gif".equals(strIcon))returnR.drawable.a_30;if("31.gif".equals(strIcon))returnR.drawable.a_31;return0;}}