@Override protected Void doInBackground(Void... pParams) { try { List<VeloFavori> velosFavoris = TransportsBordeauxApplication.getDataBaseHelper().select(new VeloFavori()); Collection<String> ids = new ArrayList<String>(); for (VeloFavori favori : velosFavoris) { ids.add(favori.number); } Collection<Station> stationsTmp = Station.recupererStations(); synchronized (stations) { stations.clear(); for (Station station : stationsTmp) { if (ids.contains(Integer.toString(station.id))) { stations.add(station); } } Collections.sort( stations, new Comparator<Station>() { public int compare(Station o1, Station o2) { return o1.name.compareToIgnoreCase(o2.name); } }); } } catch (TbcErreurReseaux exceptionReseau) { erreurReseaux = true; } return null; }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); Station station; VeloFavori veloFavori; switch (item.getItemId()) { case R.id.supprimerFavori: station = (Station) getListAdapter().getItem(info.position); veloFavori = new VeloFavori(); veloFavori.number = Integer.toString(station.id); TransportsBordeauxApplication.getDataBaseHelper().delete(veloFavori); ((VeloAdapter) getListAdapter()).getStations().remove(station); ((BaseAdapter) getListAdapter()).notifyDataSetChanged(); return true; default: return super.onOptionsItemSelected(item); } }