ユーザーが名前のリストを表示できるアプリに取り組んでおり、ユーザーがリストをクリックすると、選択したプロファイルに関する詳細が別のアクティビティに表示されます。私はリストビューを持っています。次のコードを使用して作成します。
listContacts = (ListView) findViewById(R.id.listContacts);
data = new ArrayList<HashMap<String, String>>();
db = new DatabaseHandler(this);
List<Contact> contacts = db.getAllContacts();
List<String> names = new ArrayList<>();
List<String> sex = new ArrayList<>();
List<String> age = new ArrayList<>();
List<Integer> id = new ArrayList<>();
List<String> sexnage = new ArrayList<>();
for (Contact cn : contacts) {
names.add(cn.getName() + " " + cn.getSurname());
sex.add(cn.getSex());
age.add(cn.getAge());
id.add(cn.getID());
sexnage.add(cn.getSex() + " " + cn.getAge());
}
titleArray = new String[names.size()];
titleArray = names.toArray(titleArray);
subItemArray = new String[sexnage.size()];
subItemArray = sexnage.toArray(subItemArray);
for(int i=0;i<titleArray.length;i++){
HashMap<String,String> datum = new HashMap<String, String>();
datum.put("Name", titleArray[i]);
datum.put("Sex and Age", subItemArray[i]);
data.add(datum);
}
SimpleAdapter subAdapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2,
new String[] {"Name", "Sex and Age"}, new int[]
{android.R.id.text1, android.R.id.text2});
listContacts.setAdapter(subAdapter);
リスト内の各要素の ID をデータベース 1 に対応するように設定するにはどうすればよいですか?