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