我只是试图将json web-service解析为一个数组,问题只是list-view上显示的第一个项目。我应该怎么做才能生成完整的json数组出现在列表视图中?
private void makeJsonObjectRequest() {
showpDialog();
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
urlJsonObj, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
try {
JSONArray snap = response.getJSONArray("arr_0");
String[] list = new String[snap.length()];
for (int i = 0; i < snap.length(); i++) {
list[i] = snap.getJSONObject(i).getString("title");
list[i] = snap.getJSONObject(i).getString("description");
list[i] = snap.getJSONObject(i).getString("url");
list[i] = snap.getJSONObject(i).getString("sort");
list[i] = snap.getJSONObject(i).getString("attachment_id");
list[i] = snap.getJSONObject(i).getString("thumb");
list[i] = snap.getJSONObject(i).getString("image");
list[i] = snap.getJSONObject(i).getString("height");
list[i] = snap.getJSONObject(i).getString("width");
}
snapActivity.this.lv.setAdapter(new ArrayAdapter(snapActivity.this,android.R.layout.simple_list_item_1, list));
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
}
答案 0 :(得分:0)
我已经弄明白了,你只需要使用自定义适配器将数据填充到listView