伙计们
我正在尝试将 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 行,我想在显示视图中查看第 5 行的属性
我是 Java 和 android 的新手
我认为我应该将位置添加到 getTitle(position)
获取时 < 因为在 iOS 开发中,我将数组 objectAtIndex:int 的数据传递给 NSDic
就这样
但是这里<我不知道
提前致谢