次の形式のリモートJSONデータを使用してListViewにデータを入力しています。
{"nodes":[{"node":{"title":"Article#1","id":"4"}},{"node":{"title":"Article#2","id":"3"}}]}
私のListViewは、次のコードで構成されています。
ArrayList<String> articles = new ArrayList<String>();
try{
for(int i=0; i < data.length(); i++){
JSONObject dataObj = (JSONObject)data.get(i);
JSONObject record = dataObj.getJSONObject("node");
title = (record.getString("title"));
nid = (record.getString("nid"));
Log.i("FOUND", "title: " + title);
Log.i("FOUND", "nid: " + nid);
articles.add(title);
}
}catch(JSONException j){
Log.e("CHECK", "Attempting to read data returned from JSONReader: " + j.toString());
}
ListView articlesList = (ListView)findViewById(R.id.articlesList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ArticlesActivity.this, R.layout.article_item, R.id.articleItem, articles);
articlesList.setAdapter(adapter);
プロセス全体が機能し、記事のタイトルが正常に一覧表示されます。しかし、私は各リスト項目でonSelectListenersを有効にするのに役立つチュートリアルに従おうとしています。各記事のタイトルに関連付けられているID要素は、記事のコンテンツをリモートで取得するために必要なすべてです。
タイトルとIDデータの両方を含むようにArrayListを設定し、それを使用して動的なOnSelectListener対応のListViewを設定することは可能ですか?