歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android調用webservice實現手機歸屬查詢

Android調用webservice實現手機歸屬查詢

日期:2017/3/1 10:08:32   编辑:Linux編程

Android中的webservice調用方式與java中差異較大,經過查找些資料和例子,自己這邊兒就做了個總結,寫了個例子,談不上原創(慚愧ing...),不過這方面的例子確實都大體相似,因為大家能寫成博文的,發布成例子的,調用的接口大抵是網上公開的接口,如天氣啊,手機號碼段啊之類的,公司內部的接口,肯定是不能外透的,但是調用的方式確實一樣,所以記錄下來,方便大家研究,或者自己今後用到。

老習慣,先上效果圖:

圖一

圖二

再上項目結構圖:

第一步,加入調用webservice的jar包,ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar,下面會提供附件下載。

第二步,編輯activity_main.xml布局出效果圖一所示效果,代碼如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:paddingTop="5dip"
  7. android:paddingLeft="5dip"
  8. android:paddingRight="5dip"
  9. >
  10. <TextView
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:text="手機號碼(段):"
  14. />
  15. <EditText android:id="@+id/phone_sec"
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:inputType="textPhonetic"
  19. android:singleLine="true"
  20. android:hint="例如:1398547"
  21. />
  22. <Button android:id="@+id/query_btn"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:layout_gravity="right"
  26. android:text="查詢"
  27. />
  28. <TextView android:id="@+id/result_text"
  29. android:layout_width="wrap_content"
  30. android:layout_height="wrap_content"
  31. android:layout_gravity="center_horizontal|center_vertical"
  32. />
  33. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved