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
| public class tuto extends Activity
{
/** Déclaration des variables */
private ListView maListView;
private ArrayList<HashMap<String, String>> maArrayList = new ArrayList<HashMap<String, String>>();
private HashMap<String, String> map;
private SimpleAdapter mSchedule;
/**Programme principal */
//@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Je recupere les references de mes objets */
maListView = (ListView)findViewById(R.id.maListView);
/** Je creer une liste de STRING */
map = new HashMap<String, String>();
//on rempli le premier item
map.put("titre", "Mon premier mémo");
map.put("description", "Faire les courses\nessai\nblablablablablabla");
map.put("date", "Création :\n26/12/1975");
map.put("alarme", "Alarme : non");
//on ajoute le hasmap à maListView
maArrayList.add(map);
map = new HashMap<String, String>();
//on rempli le premier item
map.put("titre", "Mon deuxieme mémo");
map.put("description", "Faire la fête \nessai\nblablablablablabla");
//on ajoute le hasmap à maListView
maArrayList.add(map);
/** Je creer un adaptateur pour lier la ArrayList a ma ListView */
mSchedule = new SimpleAdapter (this.getBaseContext(), maArrayList, R.layout.affichagemalistview,
new String[] {"titre", "description"}, new int[] {R.id.titre, R.id.description});
/** je lie les deux */
maListView.setAdapter(mSchedule);
maListView.setLongClickable(true);
//Enfin on met un écouteur d'évènement sur la listView
maListView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> a, View v, int position, long id)
{
//on récupère la HashMap contenant les infos de la listView (titre, description)
HashMap<String, String> map = (HashMap<String, String>) maListView.getItemAtPosition(position);
//on créer une boite de dialogue
/** Préparation de ma fenêtre perso */
LayoutInflater factory = LayoutInflater.from(tuto.this);
View alertDialogView = factory.inflate(R.layout.descriptionmemo, null);
AlertDialog.Builder adb = new AlertDialog.Builder(tuto.this);
//On affecte la vue personnalisé
adb.setView(alertDialogView);
//On donne un titre à l'AlertDialog
adb.setTitle(map.get("titre"));
TextView monTextView = (TextView)alertDialogView.findViewById(R.id.TextView1);
String essai = map.get("description");
monTextView.setText(essai);
//On affecte un bouton "OK" à notre AlertDialog et on lui affecte un évènement
adb.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
adb.show();
}
});
maListView.setOnItemLongClickListener(new OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(AdapterView<?> a, View v, int position, long id)
{
Toast.makeText(tuto.this, "clic long", 1000).show();
return false;
}
});
} |
Partager