Android调用天气预报的WebService简单例子

这篇博客详细介绍了如何在Android应用中调用天气预报的WebService。首先,进行了主界面布局;接着,导入KSOAP2库并配置;然后,指定WebService命名空间和方法,设置调用参数;创建SOAP请求,使用HttpTransportSE对象调用服务;处理返回结果,并解决Android网络访问权限问题。最后,展示了完整的SOAPUtil类和WeatherActivity的事件处理代码。
摘要由CSDN通过智能技术生成

阶段一:进行主界面布局,如下图:

                                                  

具体代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/ba">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/input_city" />
    <EditText 
        android:id="@+id/city"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <Button 
        android:id="@+id/search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/search"/>

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

阶段二:导入KSOAP包.

将ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar包拷贝到libs文件夹下,然后点击右键Build Path –> Configure Build Path...,会出现

然后将添加的包勾上...

阶段三&

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值