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 45 46 47 48 49
| private ListView listView;
private ArrayList<HashMap<String, String>> liste;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GestionBD gestionBD = new GestionBD(this);
LitFichier litFichier = new LitFichier();
litFichier.execute("http://192.168.1.16/livraisons.xml");
try {
if (litFichier.get())
{
gestionBD.init(litFichier.getLivraisons());
listView = (ListView) findViewById(R.id.listView1);
liste = gestionBD.donneInfo();
SimpleAdapter adapter = new SimpleAdapter(this, liste, R.layout.liste_client,
new String[] {"client", "adresse", "nbColis" ,"mtTotal"},
new int[] {R.id.client, R.id.adresse, R.id.nbColis, R.id.mtColis });
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
else
Log.i("lithttp", "Problème lecture fichier");
} catch (InterruptedException e) {
Log.i("lithttp", "Interruption lecture fichier");
} catch (ExecutionException e) {
Log.i("lithttp", "Problème exécution");
}
}
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "cliqué sur "+
((HashMap<String, String>) listView.getAdapter().getItem(position)).get("client"),
Toast.LENGTH_SHORT).show();
Collections.swap(liste, position, position-1); //nécessite d'avoir accès à ta variable liste (ArrayList) depuis ici
listView.getAdapter().notifyDataChanged();
}
} |
Partager