wenserver获取天气预报数据实例分享

时间:2021-05-19

复制代码 代码如下:
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:///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>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章