0
我設法獲取JSONData到的ListView
它工作正常,,但問題是我要每行的JSON數據傳遞到下一個視圖
這裏的,我的JSON類
public class GetJSON extends AsyncTask<String, Void, ArrayList<JSONFields>> {
@Override
protected ArrayList<JSONFields> doInBackground(String... params) {
// TODO Auto-generated method stub
try {
String url = params[0];
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
response = client.execute(get);
InputStream content = response.getEntity().getContent();
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(content));
String line;
String json = "";
while ((line = reader.readLine()) != null) {
json += line;
}
JSONArray array = new JSONArray(json);
ArrayList<JSONFields> alData = new ArrayList<JSONFields>();
for (int i = 0; i < array.length(); i++) {
obj = array.getJSONObject(i);
data = new JSONFields();
data.setID(obj.getString("id"));
data.setTitle(obj.getString("title"));
data.setImage(obj.getString("image"));
data.setYoutube(obj.getString("youtube"));
data.setLength(obj.getString("length"));
alData.add(data);
}
System.out.println("Data returned sucessfully");
return alData;
} 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();
}
return null;
}
@Override
protected void onPostExecute(ArrayList<JSONFields> result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
CustomAdapter adapter = new CustomAdapter(MainApp.this, result);
listview.setAdapter(adapter);
}
}
和我有控股JSON數據字段
創建類這
公共類JSONFields {
private String id;
private String title;
public String getID() {
return id;
}
public void setID(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
,但是當我通過這段代碼
String thetitle = data.getTitle();
Intent showView = new Intent(MainApp.this, Show.class);
showView.putExtra("title", thetitle);
startActivity(showView);
我只得到了最後一排信息..
這是我的問題
我想如果我點擊行5看到行的attr 5顯示查看
我是新來的Java和Android
,我想我應該在的位置添加到的getTitle(位置)
越來越<時,因爲iOS的開發,我通過陣列的數據objectAtIndex:int在NSDic
這一切
但這裏<我不知道
在此先感謝
我已經使用onItem但同樣的問題 – KratosCode
amm如何使用該..亞阿我想項目點擊ListView – KratosCode