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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| public class Main3 extends ListActivity implements OnClickListener {
FormationBDD formationBdd;
Formation liste;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultat_list);
// On récupère l'intent qui a lancé cette activité
Intent i = getIntent();
String ville = i.getStringExtra(Main2.VILLE);
String catégorie = i.getStringExtra(Main2.CATEGORIE);
formationBdd = new FormationBDD(this);
formationBdd.open();
// liste = formationBdd.getFormation(ville, catégorie);
// if (liste == null)
// Toast.makeText(Main3.this, "liste de formation vide ", Toast.LENGTH_LONG).show();
// else
DataBind(ville, catégorie);
registerForContextMenu(getListView());
}
@Override // Création du menu principal
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,100,0,"Tout effacer");
return true;
}
@Override // Selection d'un item du menu
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case 100:
//db.Truncate();
//DataBind();
break;
}
return true;
}
@Override // Selection d'un item de la liste
protected void onListItemClick(ListView l, View v, int position, long id) {
//Cursor cursor = (Cursor)l.getAdapter().getItem(position);
//String titre = cursor.getString(cursor.getColumnIndex("libellé"));
//Toast.makeText(this,"Item id "+id+" : "+titre, Toast.LENGTH_SHORT).show();
//super.onListItemClick(l, v, position, id);
}
@Override // Creation du menu contextuel
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Action");
menu.add(0,100,0,"Call");
menu.add(0,200,1,"More details");
menu.add(0, 300, 3, "Localisation");
menu.add(0,400,2,"send mail");
}
@Override // Selection d'un item du menu contextuel
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()){
case 100:
String tel = item
Intent appel = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+ tel));
startActivity(appel);
break;
case 200:
Toast.makeText(this, "TODO", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
@Override
protected void onDestroy() {
// db.close();
super.onDestroy();
}
public void DataBind(String ville, String catégorie){
Cursor c = formationBdd.recupererChoixFormations(ville, catégorie);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.list1,c,new String[]{"libellé","adresse","tel"},
new int[]{R.id.textLibellé,R.id.TextAdresse,R.id.TextTel});
setListAdapter(adapter);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
} |
Partager