通过调用webservice实现查询天气预报系统

该博客展示了如何在Android应用中使用KSOAP2库调用WebService接口查询天气预报。通过MainActivity类,输入城市名,获取并显示天气图标和当前天气状况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MainActivity
package com.example.weather;

import java.net.MalformedURLException;
import java.net.URL;

import org.ksoap2.serialization.SoapObject;

import weatherforecast.soap.SoapUtil;
import weatherforecast.tools.ImageTool;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText city;
	private ImageView weatherIcon;
	private TextView weatherToday;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        city=(EditText) this.findViewById(R.id.editText1);
        weatherIcon=(ImageView) this.findViewById(R.id.imageView1);
        weatherToday=(TextView) this.findViewById(R.id.textView2);
    }
    public void getWeather(View view){
    	Toast.makeText(this, "欢迎使用天气预报系统", 5).show();
    	String theCityName=city.getText().toString();
    	String wsdlUrl="http://www.webxml.com.cn/webservices/weatherwebservice.asmx";
        String webMethod="getWeatherbyCityName";
    	SoapObject result=(SoapObject) SoapUtil.doTra
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值