これは、json配列からデータを接続してプルすることです。2つのリストビューアイテムを追加しましたが、テキストは表示されていませんか?
JSON配列{"tournaments":[{"Title": "my title"、 "Contact": "my contact"、 "Description": "my description"、 "City": "my city"、 "State": " Kansas "、" Category ":" Roulette "}、{" Title ":" my title "、" Contact ":" my contact "、" Description ":" my description "、" City ":" my city "、" State ":" Connecticut "、" Category ":" Three Card Poker "}]}
そして、Javaの私のコードのいくつか...
JSONObject json = JSONfunctions.getJSONfromURL("http://kleinefrosch.com/retrieve.php");
try{
JSONArray tourneys = json.getJSONArray("tournaments");
for(int i=0;i<tourneys.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = tourneys.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Title:" , e.getString("Title"));
map.put("Contact:" , e.getString("Contact"));
map.put("Description:" , e.getString("Description"));
map.put("City:" , e.getString("City"));
map.put("State:" , e.getString("State"));
map.put("Country:" , e.getString("Country"));
map.put("Category:" , e.getString("Category"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main,
new String[] { "Title","Contact","Description","City","State","Country","Category" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(JsonActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
}