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
| Map<String, String[]> dictionnaire = new HashMap<String, String[]>(); //var globale
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
try { searchAnnoncePerso(); }
catch (ClientProtocolException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
catch (JSONException e) { e.printStackTrace(); }
}
public void searchAnnoncePerso() throws ClientProtocolException, IOException, JSONException{
String URL = "....";
new rest(1,URL,null);
JSONObject jsonReponse = rest.getjObject();
//jsonReponse = {"tab":{"ID":"1","Name":"toto"},{"ID":"4","Name":"mickey"}};
JSONArray itemArray = jsonReponse.getJSONArray("tab");
int nbItemArray = itemArray.length();
ListView laListe = (ListView)findViewById(R.id.lvList);
String[] TabName = new String[nbItemArray];
String[] TabId = new String[nbItemArray];
for (int i=0;i != nbItemArray; i++) {
TabName[i] = itemArray.getJSONObject(i).getString("Name");
TabId[i] = itemArray.getJSONObject(i).getString("ID_Annonce");
}
laListe.setOnItemClickListener(this);
dictionnaire.put("Nom", TabName); dictionnaire.put("ID", TabId);
laListe.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TabName));
}
@Override public void onItemClick(
AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent Nextintent = new Intent();
Nextintent.setClass(this, detailAnnonces.class);
Nextintent.putExtra("ID", dictionnaire.get("ID")[position]);
startActivity(Nextintent);
} |
Partager