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
|
try {
for(int i=0;i<result.length();i++){
JSONObject json_data = result.getJSONObject(i);
element.add(createItem("ELEMENT N°"+json_data.getInt("id"), "NAME : "+json_data.getString("name")+ "\nNAME2 : "+json_data.getString("name2")));
}
// creation de la liste personalisée et de l'adapter
SeparatedListAdapter adapter = new SeparatedListAdapter(Activity.this);
adapter.addSection("Liste des éléments", new SimpleAdapter(Activity.this, element, R.layout.list_complex,
new String[] { ITEM_TITLE, ITEM_CAPTION1 }, new int[] { R.id.list_complex_title, R.id.list_complex_caption1 }));
//Affichage de la liste
ListView list = new ListView(Activity.this);
list.setAdapter(adapter);
Activity.this.setContentView(list);
// ListView Item Click Listener (Lorsque l'on clique sur la liste)
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(ticketReadActivity.this, DetailTicketActivity.class);
//Ici je voudrai récupérer l'ID inséré plus haut genre : element.get(id);
intent.putExtra("idEntry", id);
startActivity(intent);
}
}); |
Partager