解析JSON数据并添加微调器

时间:2013-03-04 08:12:42

标签: java android android-arrayadapter android-spinner

我创建了一个从JSON中提取数据的活动,并且Spinner视图中没有显示数据,但是当我尝试在logcat上打印数据时,会显示数据。

这是我的代码:

Log.e("", "Response for Parsing :" + Eye_Activity.strResponse2);
Log.e("ID OF DR", it.getStringExtra("dr_IDD"));

try {
    JSONObject mainJsonObject = new JSONObject(
            Eye_Activity.strResponse2.trim());
    JSONArray jsonarray = mainJsonObject.getJSONArray("dr_date");
    System.out.println("Hello");
    Log.e("JSON", "!!!!!!!");
    final String[] items = new String[jsonArray.length()];
    Log.e("", "jsonarray length" + jsonArray.length());
    for (int i = 0; i < jsonArray.length(); i++) {
        if (jsonarray.getJSONObject(i).has("dr_date")) {
            JSONObject c = jsonArray.getJSONObject(i);
            String dateString = c.getString(KEY_DATEE);
            items[i] = c.getString(KEY_DATEE);
            System.out.println("Hello Events:" + items);
            Log.e("Hello Events:", "->" + items);
        }
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dateSpinner.setAdapter(adapter);
} catch (JSONException jee) {
    jee.printStackTrace();
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}

0 个答案:

没有答案