Android实现快递单号查询快递状态信息

  

今天介绍一个自己做的快递单号查询的简单程序,供大家参考。由于需要使用http和json,本文在build.gradle(模块:应用)添加了okhttp3依赖和gson依赖。

        依赖关系{   编译fileTree(包括:[' *。jar”, dir:“填词”)   androidTestCompile (2.2.2 com.android.support.test.espresso: espresso-core:, {   排除集团:“com.android。支持”模块:“support-annotations”   })   编译“com.android.support: appcompat-v7:24.1.1”   testCompile“junit: junit: 4.12”   编译的com.squareup.okhttp3: okhttp: 3.6.0   编译的com.google.code.gson: gson: 2.2.4”   }      

看一下布局文件
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android: paddingBottom=" @dimen/activity_vertical_margin”   android: paddingLeft=" @dimen/activity_horizontal_margin”   android: paddingRight=" @dimen/activity_horizontal_margin”   android: paddingTop=" @dimen/activity_vertical_margin”   android:取向=按怪薄?   工具:上下文=癱om.yjp.deliverynoquerydemo.MainActivity”比;      & lt;旋转器   android: id=癅 + id/delivery_company_spinner”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_margin=" 5 dp "   android:条目=癅array/delivery_company”/比;      EditText & lt;   android: id=癅 + id/delivery_no_edit_text”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_margin=" 5 dp "   android:提示=" @string/please_enter_delivery_no”   android: inputType="数量"/比;      & lt;按钮   android: id=癅 + id/query_button”   android: layout_gravity="中心"   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_margin=" 5 dp "   android:文本=癅string/查询”/比;      & lt;列表视图   android: id=癅 + id/messages_list_view”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_margin=" 5 dp "   android: listSelector=癅android:颜色/透明/比;   & lt;/LinearLayout>之前      

, ListView使用的物品的布局

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄?   android: layout_width=" match_parent "   android: layout_height=癿atch_parent”比;      & lt; TextView   android: id=癅 + id/time_text_view”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: textStyle=按蟮ā?   android: textAppearance=" & # 63; android: textAppearanceMedium”   android:字体="等宽字体"/比;      & lt; TextView   android: id=癅 + id/context_text_view”   android: layout_width=" match_parent "   android: layout_height=" 50 dp”   android: textAppearance=" & # 63; android: textAppearanceSmall”   android:字体="等宽字体"/比;      & lt;/LinearLayout>之前      

资源文件,首先是strings.xml

        & lt; resources>   & lt;字符串名称=" app_name "祝辞快递查询& lt;/string>   & lt;字符串名称=" please_enter_delivery_no "祝辞请输入快递单号& lt;/string>   & lt;字符串名称="查询"祝辞查询& lt;/string>   & lt;字符串名称=皅uery_url”在http://www.kuaidi100.com/query   & lt;/resources>   之前      

这里我们使用了快100的递接口,然后看看arrays.xml

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; resources>   & lt;字符串数组的名字=癲elivery_company”比;   & lt; item>顺丰& lt;/item>   & lt; item> EMS   & lt; item>快捷& lt;/item>   & lt;/string-array>      & lt;字符串数组的名字=癲elivery_company_id”比;   & lt; item> shunfeng   & lt; item> ems   & lt; item> kuaijiesudi   & lt;/string-array>   & lt;/resources>   之前      

只做了3个快递公司的查询,还有很多其他的支持,界面如图所示

Android实现快递单号查询快递状态信息