json 배열에서 데이터를 연결하고 당깁니다. 두 개의 목록보기 항목을 추가했지만 텍스트가 표시되지 않습니까?왜 내 목록보기에 데이터가 나타나지 않습니까?
{ "tournaments": [{ "제목": "내 제목", "연락처": "내 연락처", "설명" "상태": "캔자스", "범주": "룰렛"}, { "제목": "내 제목", "연락처": "내 연락처", "설명": "내 설명", "도시" 나의 도시 ","주 ":"코네티컷 ","카테고리 ":"세 카드 포커 "}]}
그리고 자바에서 내 코드의 일부 ...
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();
}
});
}
}
업데이트 왜이 사람들은 저와 일하지 않습니까? 우리는 동일한 예제 코드를 사용하고 있습니다. http://stackoverflow.com/questions/7155322/parse-json-data-into-listview – user1411823