android呼叫webXml 查詢發車站和到達站查詢火車時刻表
呼叫webxml上的介面,自己製作了一款小軟體,支援查詢車站列表。運用了asynchttpclient,調取介面,把接受到的資料轉換為json型別,用map存取,放到listView
下載地址:http://download.csdn.net/detail/kentlee114/8645033
</pre><pre name="code" class="java">
public class MainActivity extends Activity { protected String str1; protected String current; protected JSONObject jsonObj; protected String json_result; private ListView mListView; ArrayList<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>(); private SimpleAdapter arr; private ImageButton searchBtn; private EditText start; private EditText end; private ProgressDialog pd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView =(ListView)findViewById(R.id.listView1); searchBtn =(ImageButton)findViewById(R.id.search); start =(EditText)findViewById(R.id.editText1); end =(EditText)findViewById(R.id.editText2); pd = new ProgressDialog(this); String[] from = new String[]{"trainCode","first","last","start","end", "startTime","arriveTime","km","date"}; int[] to = new int[]{R.id.number,R.id.place,R.id.lastPlace,R.id.current,R.id.currentDes, R.id.startTime,R.id.arriveTime,R.id.total,R.id.pauseTime}; arr = new SimpleAdapter(this, dataList, R.layout.eyd_cargo_item,from,to); mListView.setAdapter(arr); searchBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub dataList.clear(); getData(); } }); } //獲取資料 private List< Map<String, Object>> getData() { AsyncHttpResponseHandler handler = new AsyncHttpResponseHandler(){ @Override public void onStart() { super.onStart(); pd.setMessage("載入中..."); pd.setCanceledOnTouchOutside(false); pd.show(); } @SuppressWarnings("unchecked") public void onSuccess(String arg0) { super.onSuccess(arg0); pd.dismiss(); //把xml轉為json try { jsonObj = XML.toJSONObject(arg0); json_result = jsonObj.toString(); Log.d("XML", jsonObj.toString()); } catch (JSONException e) { e.printStackTrace(); } Gson gson = new Gson(); HashMap<String, Object> map = gson.fromJson((String) json_result, new TypeToken<Map<String, Object>>() {}.getType()); Map<String,Object> map_dataSet = (Map<String, Object>) map.get("DataSet"); Map<String,Object> map_diff = (Map<String, Object>) map_dataSet.get("diffgr:diffgram"); Map<String,Object> map_station = (Map<String, Object>) map_diff.get("getStationAndTime"); Object tables = map_station.get("TimeTable"); Class<? extends Object> type = tables.getClass(); if(!type.getSimpleName().equals("LinkedHashMap")){ //先判斷型別 List<Map<String,Object>> stationList = (List<Map<String, Object>>) map_station.get("TimeTable"); //迴圈遍歷資料 for(Map<String,Object> mm : stationList){ // 定義一個map用來存放資料 Map<String, Object> hashMap = new HashMap<String, Object>(); hashMap.put("trainCode", "列車號:"+mm.get("TrainCode")); hashMap.put("first", "始發站:"+mm.get("FirstStation")); hashMap.put("last", "終點站:"+mm.get("LastStation")); hashMap.put("start", "發車站:"+mm.get("StartStation")); hashMap.put("end","到達站:"+ mm.get("ArriveStation")); hashMap.put("startTime", "發車時間:"+mm.get("StartTime")); hashMap.put("arriveTime", "到達時間:"+mm.get("ArriveTime")); hashMap.put("km", "里程:"+mm.get("KM")+"Km"); hashMap.put("date","歷時:"+ mm.get("UseDate")); dataList.add(hashMap); } arr.notifyDataSetChanged(); }else{ Map<String,Object> map_err = (Map<String, Object>) map_station.get("TimeTable"); String error =map_err.get("FirstStation").toString(); Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Throwable arg0, String arg1) { super.onFailure(arg0, arg1); pd.dismiss(); Toast.makeText(getApplicationContext(), arg1, Toast.LENGTH_SHORT).show(); }; }; RequestParams params = new RequestParams(); //不輸入字元,預設北京到上海 params.put("StartStation", start.getText().toString()); params.put("ArriveStation", end.getText().toString()); params.put("UserID", ""); HttpUtil.post("/getStationAndTimeByStationName", params, handler); return dataList; } }
</pre><pre name="code" class="java"> <pre name="code" class="html">xml檔案 <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" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/tv_end" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_toRightOf="@+id/et1" android:text="起始站" /> <EditText android:id="@+id/editText1" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/tv_end" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText1" android:layout_alignBottom="@+id/editText1" android:layout_toRightOf="@+id/editText1" android:text="目的地" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toLeftOf="@+id/search" android:layout_toRightOf="@+id/textView1" android:ems="10" /> <ImageButton android:id="@+id/search" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentRight="true" android:contentDescription="search" android:layout_centerVertical="true" android:background="@drawable/search_bar" /> </RelativeLayout> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" > </ListView> </LinearLayout>
相關推薦
android呼叫webXml 查詢發車站和到達站查詢火車時刻表
呼叫webxml上的介面,自己製作了一款小軟體,支援查詢車站列表。運用了asynchttpclient,調取介面,把接受到的資料轉換為json型別,用map存取,放到listView下載地址:http://download.csdn.net/detail/kentlee11
Oracle中使用join表連線查詢代替 in和not in 查詢
首先,在oracle中效率排行:表連線>exist>not exist>in>not in,而且使用in查詢會有查詢條件數量不能超過1000的限制;因此如果簡單提高效率可以用exist代替in進行操作,當然換成表連線可以更快地提高效率,具體是用le
Mysql學習總結(24)——MySQL多表查詢合併結果和內連線查詢
1、使用union和union all合併兩個查詢結果:select 欄位名 from tablename1 union select 欄位名 from tablename2; 注意這個操作必須保證兩張表字段相同,欄位資料型別也相同。另外,使用union的時候會去除重複(相
ElasticSearch term和match查詢機制解析和隱藏的查詢問題
2. 關於預設分析使用term查詢的問題 之前說過es的預設分析器會講中文拆分成一個個的單個漢子,搜尋條件“內科”會被分析為“內”和“科”,從而進行搜尋。而對於搜尋我們常用的match搜尋類似於資料庫的模糊查詢,term搜尋為精確查詢。使用的時候會出現以下
二叉樹的遞迴建立,以及二叉查詢樹查詢的建立 和遍歷查詢的比較
二叉樹的遞迴建立 、以及二叉查詢樹查詢的建立 和遍歷查詢的比較 (1)二叉樹的遞迴建立和二叉樹的陣列表示法非常相似,可參考二叉樹的陣列建立 (2)二叉查詢樹的特性 1)每一個結點的值都不相同,也就是說整棵樹中的每一個結點都擁有不同的值。 2)每一
解決 df -h 查詢的儲存和du -sh * 查詢的儲存總和 不對等問題
今天感覺伺服器很卡,用df -h 查看了下儲存,發現 “/” 根目錄已經爆滿。 df -h du -sh * 但使用du -sh * 發現根目錄檔案佔用的儲存並不大。這是為何?????? 回想以前是吧大的日誌檔案刪除過,難道是沒有真正的刪除造成的?
關係型資料庫查詢語言 SQL 和圖資料庫查詢語言 nGQL 對比
摘要:這篇文章將介紹圖資料庫 Nebula Graph 的查詢語言 nGQL 和 SQL 的區別。 > 本文首發於 Nebula Graph 官方部落格:https://nebula-graph.com.cn/posts/sql-vs-ngql-comparison/ ![sql-vs-ngql](
Android呼叫系統的打電話和發簡訊功能
一、打電話 1、新增打電話的許可權在manifast檔案中。 <uses-permission android:name="android.permission.CALL_PHONE"/> 2、使用Uri.parse(S
Android呼叫系統打電話和發簡訊功能
一、打電話 1、新增打電話的許可權在manifast檔案中。 <uses-permission Android:name="android.permission.CALL_PHONE"/> 2、使用Uri.par
30、Java並發性和多線程-阿姆達爾定律
開發者 dup 算術 currency 優化 blog 進行 變量 自己的 以下內容轉自http://ifeve.com/amdahls-law/: 阿姆達爾定律可以用來計算處理器平行運算之後效率提升的能力。阿姆達爾定律因Gene Amdal 在1967年提出這個定律而得
Android外掛化技術之旅 1 開篇 - 實現啟動外掛與呼叫外掛中的Activity和Service
前言 Android技術如今已很成熟了,元件化、外掛化、熱修復等等框架層出不窮,如果只停留在單純的會用框架上,技術永遠得不到成長,只有懂得其原理,能夠婉婉道來,能夠自己手動寫出,技術才會得到成長,與其焦慮未來,不如把握現在。本篇將手寫教大家寫出外掛化框架,外掛化技術是Android高階工程師必備的技術之一,
Android 百度地圖開發(一)如何呼叫百度地圖介面和在專案中顯示百度地圖以及實現定位
二、下載百度地圖API庫 然後新增到專案中即可。 三、在專案清單AndroidMainifest.xml配置百度地圖API key和新增相關許可權 四、在專案呼叫百度地圖專案功能,這篇文章就首先講講顯示地圖和定位的功能 首先
android adb shell 模擬廣播發送和鍵值事件
1.模擬傳送廣播adb shell am broadcast -a 定義的廣播action string2.模擬上下左右 確定鍵值adb shell input keyevent "value"va
Android開發:仿微信和QQ空間發說說相簿讀取、拍照、圖片裁剪和圖片上傳伺服器等功能的實現
第一步:新增依賴包: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.2.1' compile project('
Android呼叫系統相機和相簿
拍照和相簿的功能在實際開發中是最常見的功能,這裡記錄下。 準備工作 許可權 1234 <!-- 往SDCard寫入資料許可權 --> <uses-permission android:name="android.permission.WRIT
Android呼叫系統圖庫和相機獲取圖片並裁剪
最近用到從系統圖庫和相機獲取圖片並裁剪當頭像,根據郭霖大神的第一行程式碼呼叫相機和圖冊,來進行擴充套件和總結。 1、獲取許可權 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORA
Android呼叫系統照相機和攝像機
呼叫系統照相機。 private void callPhone() { //獲得檔案 File _file = new File(StorageUtils.getCacheDirectory
iOS應用呼叫系統打電話、發簡訊和發郵件功能
摘要: 在應用程式內,呼叫系統的功能來實現打電話、發簡訊和發郵件,通過電話號碼或者郵箱,直接跳轉到系統的功能介面。 PS:除錯好像只能真機除錯,模擬器沒有反應,真機就可以跳轉,不知道是不是必須真機,但方法肯定是可行的。 1、打電話 應用內呼叫系統打電話有兩種方式: 1
Android手機發送和監聽UDP資料
UDP協議中文名是使用者資料報協議,在網路中它與TCP協議一樣用於處理資料包,是一種無連線的協議。在OSI模型中,在第四層——傳輸層,處於IP協議的上一層。與所熟知的TCP(傳輸控制協議)協議一樣,UDP協議直接位於IP(網際協議)協議的頂層。根據OSI(開放系統互連)參考
操作Android中聯絡人,通話記錄,短息,的URI,和具體的查詢語句,欄位註解。(根據自己需求)
讀取簡訊的URI: /** * 所有的簡訊 */ public static final String SMS_URI_ALL = "content://sms/"; /** * 收件箱簡訊 */ public sta