0

对不起我的英语不好。我是新的机器人。

JSON在Android中有一些问题

(1.)我一直在网上获取信息( JSON)。如何在特定页面上标记 googlemap 上的所有站点?

(2.1) 我一直在从 Internet( JSON) 获取信息并在 listView 中显示这些信息。这个listView由两个TextView(txtV1,txtV2)组成。如何使用keyword_search 来过滤ListVieweditText?

(2.2) 如果我点击该选项,相关信息将被传送到下一页并显示。现在,我只能捆绑字符串数据。如何捆绑(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();
            }
        }
    }
4

2 回答 2

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

要传递 lat/long trough Bundle,请在从 JSON 获取时通过调用JSONObject#getLong解析它们,或者在其他 Activity 中解析它们Long#parseLong

于 2014-07-11T10:20:35.340 回答
0

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

您可能想看看我的源代码并了解如何操作: https ://github.com/le-moulin-studio/bike-friend/blob/master/android/src/main/java/com/ lemoulinstudio/bikefriend/ubike/YouBikeStationProvider.java

于 2014-07-17T06:56:31.513 回答