我有一个惰性列表加载图像列表,此时 url 被硬编码在 String[] 中,我想通过 json 提要加载它们。所以我的问题是如何从 JsonObject 创建一个字符串 []?
这是我到目前为止所得到的
try {
post.setEntity (new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
fulldata = String.valueOf(json);
Log.v("myApp","newsdata" + fulldata);
newsList = new ArrayList<String>();
newsList2 = new ArrayList<String>();
newsList3 = new ArrayList<String>();
JSONObject obj = new JSONObject(json);
JSONObject objData = obj.getJSONObject("data");
JSONArray jArray = objData.getJSONArray("news");
for(int t = 0; t < newsAmount; t++){
JSONObject newsTitleDict = jArray.getJSONObject(t);
//this is where i want to load the images into a String[]
JSONArray ImageArray = objData.getJSONArray("news");
newsList3.add(newsTitleDict.getString("title"));
}
for(int t = 0; t < 1; t++){
JSONObject newsTitleDict = jArray.getJSONObject(t);
newsList.add(newsTitleDict.getString("title"));
newsList2.add(newsTitleDict.getString("title"));
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
arrayAdapter = new ArrayAdapter<String>(this, R.layout.single_item, newsList);
arrayAdapter2 = new ArrayAdapter<String>(this, R.layout.single_item, newsList2);
//arrayAdapter3 = new ArrayAdapter(this, R.layout.complex_item, newsList3);
String[] mStrings={
"http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter.png",
"http://a3.twimg.com/profile_images/740897825/AndroidCast-350_normal.png",
"http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
"http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
"http://a1.twimg.com/profile_images/97470808/icon_normal.png",
};
arrayAdapter3 = new LazyAdapter(this, mStrings);
ListView list = getListView();
list.setTextFilterEnabled(true);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
View header = inflater.inflate( R.layout.homeheader, list, false);
View header2 = inflater.inflate( R.layout.homeheader2, list, false);
View header3 = inflater.inflate( R.layout.homeheader3, list, false);
adapter = new MergeAdapter();
adapter.addView(header);
adapter.addAdapter(arrayAdapter);
adapter.addView(header2);
adapter.addAdapter(arrayAdapter2);
adapter.addView(header3);
adapter.addAdapter(arrayAdapter3);
setListAdapter(adapter);
}