2014-07-11 19 views
0

對不起,我的英語不好。我是新的android。JSON數據搜索和Android中的綁定

我有JSON一些問題,在Android版

(1)我已經獲得來自因特網(JSON)的信息。如何在特定頁面上的googlemap上標記所有電臺? (2.1)我一直在從互聯網上獲取信息(JSON),並在listView中顯示這些信息。這個listView由兩個TextView(txtV1,txtV2)組成。如何使用keyword_search通過editText過濾ListView

(2.2)如果點擊選項,相關信息將被傳送到下一頁並顯示。現在,我只能包裝String數據。我怎樣才能在谷歌地圖上打包(lat,lng)和標記?

這是JSON:

{ 
    "retCode": "1", 
    "retVal": [ 
    { 
     "iid": "339", 
     "sno": "0001", 
     "mday": "20140711003603", 
     "lat": "25.0408578889", 
     "lng": "121.567904444" 
    }, 
    { 
     "iid": "340", 
     "sno": "0002", 
     "mday": "20140711003508", 
     "lat": "25.041", 
     "lng": "121.556945" 
    } 
    ] 
} 

這是問題(2.1)代碼:

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.station); 
     oslist = new ArrayList<HashMap<String, String>>(); 
     new JSONParse().execute(); 
    } 

    private class JSONParse extends AsyncTask<String, String, JSONObject> { 

     private ProgressDialog pDialog; 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      sna = (TextView) findViewById(R.id.sna); 
      ar = (TextView) findViewById(R.id.ar); 
     } 

     @Override 
     protected JSONObject doInBackground(String... args) { 

      JSONParser jParser = new JSONParser(); 

      // Getting JSON from URL 
      JSONObject json = jParser.getJSONFromUrl(url); 
      return json; 
     } 

     @Override 
     protected void onPostExecute(JSONObject json) { 
      pDialog.dismiss(); 
      try { 

       // Getting JSON Array from URL 
       youbike = json.getJSONArray(TAG_retVal); 
       for (int i = 0; i < youbike.length(); i++) { 
        JSONObject c = youbike.getJSONObject(i); 

        // Storing JSON item in a Variable 
        final String iid = c.getString(TAG_iid); 
             final String sno = c.getString(TAG_sno); 
        final String mday = c.getString(TAG_mday); 
        final String lat = c.getString(TAG_lat); 
        final String lng = c.getString(TAG_lng); 

        // Adding value HashMap key => value 

        final HashMap<String, String> map = new HashMap<String, String>(); 
        map.clear(); 
        map.put(TAG_iid, iid); 
             map.put(TAG_sno, sno); 
        map.put(TAG_mday, mday); 
        map.put(TAG_lat, lat); 
        map.put(TAG_lng, lng); 

        oslist.add(map); 
        list = (ListView) findViewById(R.id.list); 

        ListAdapter adapter = new SimpleAdapter(station.this, 
          oslist, R.layout.station_list, new String[] { 
            TAG_iid, TAG_sno }, new int[] { R.id.sno, 
            R.id.iid }); 
        list.setAdapter(adapter); 

        // bundle to next page 

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

         @Override 
         public void onItemClick(AdapterView<?> parent, 
           View view, int position, long id) { 

          Intent intent = new Intent(); 
          intent.setClass(station.this, station_1.class); 

          Bundle b = new Bundle(); 

          b.putString("TAG_iid", 
            oslist.get(+position).get("iid")); 
          b.putString("TAG_sno", 
            oslist.get(+position).get("sno")); 
          b.putString("TAG_mday", 
            oslist.get(+position).get("mday")); 
          b.putString("TAG_lat", 
            oslist.get(+position).get("lat")); 
          b.putString("TAG_lng", 
            oslist.get(+position).get("lng")); 
          intent.putExtras(b); 
          startActivity(intent); 

         } 
        }); 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
+0

安置自己的logcat的? –

+0

Logcat請:) – hungr

+0

抱歉,我是菜鳥。你能教我如何發佈Logcat嗎?你想查看關於我在列表視圖(txt1,txt2)上顯示的內容的「system.out.println」信息嗎? –

回答

0

來篩選結果,看看SimpleAdapter#getFilter()。例如:

private void filterResults(CharSequence filterText){ 
    Filter filter = mSimpleAdapter.getFilter(); 
    filter.filter(filterText); 
} 
... 
mSearchBox.addTextChangeListener(new TextWatcher(){ 
    ... 
     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      filterResults(s); 
     } 
}); 

要通過經緯度/長槽Bundle,無論是分析他們JSON服用時通過調用JSONObject#getLongLong#parseLong