1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
ArrayList<Map<String, String>> list = buildData();
String[] from = { "item", "subitem" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);
ListView lv = getListView();
// Ecouteur MAIS CELUI LA NE MARCHE PAS...
lv.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// choix fait...
}
});
}
@SuppressLint("Recycle")
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
int tailletableaux = getResources().obtainTypedArray(R.array.decouvrir).length();
for (int i = 0 ; i < tailletableaux ; i++ )
list.add(putData(getResources().getStringArray(R.array.decouvrir)[i], getResources().getStringArray(R.array.decouvrirdesc)[i]));
return list;
}
private HashMap<String, String> putData(String valeur1, String valeur2) {
HashMap<String, String> items = new HashMap<String, String>();
items.put("item", valeur1);
items.put("subitem", valeur2);
return items;
} |
Partager