Android中的JSON数据搜索和绑定



对不起,我的英语不好。我是新的android。

我有一些问题的JSON在Android

(1)。我一直在从互联网(JSON)上获取信息。我如何在谷歌地图的特定页面上标记所有站点?

(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();
            }
        }
    }

要过滤结果,请查看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传递l_/long,要么在调用JSONObject#getLong从JSON中获取时解析它们,要么在使用Long#parseLong的其他活动中解析它们

您似乎正在尝试解析台北市在Android平台上的优拜单车服务的数据。我已经写过这样的代码,而且它是开源的(许可AGPL)。

你可能想看看我的源代码,看看怎么做:https://github.com/le-moulin-studio/bike-friend/blob/master/android/src/main/java/com/lemoulinstudio/bikefriend/ubike/YouBikeStationProvider.java

相关内容

  • 没有找到相关文章

最新更新