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 100 101 102 103 104 105 106
| public class Camlist extends Activity {
/** Called when the activity is first created. */
Button ajout,supp,modif,entre;
Connect con;
SimpleAdapter mSchedule;
ArrayList<String[]> ca=new ArrayList<String[]>();
String[] cc;
private ListView maListViewPerso;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
con=new Connect(this);
con.open();
ca=con.getcam();
con.close();
if(ca.size()==0)
{
setContentView(R.layout.listvide);
}
else
{
setContentView(R.layout.listcam);
//Récupération de la listview créée dans le fichier main.xml
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
// im.setImageResource(resId);
//Création de la ArrayList qui nous permettra de remplir la listView
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
for(int i=0;i<ca.size();i++)
{
//On déclare la HashMap qui contiendra les informations pour un item
HashMap<String, String> map;
//Création d'une HashMap pour insérer les informations du premier item de notre listView
map = new HashMap<String, String>();
//on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
map.put("titre", ca.get(i)[0]+" "+ca.get(i)[1]+" "+ca.get(i)[2]+" "+ca.get(i)[3]);
//on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.
//map.put("description", ca.get(i)[3]);
//on insère la référence à l'image (converti en String car normalement c'est un int) que l'on récupérera dans l'imageView
map.put("img",String.valueOf(this.getClass().getResource("cam.jpg")));
//enfin on ajoute cette hashMap dans la arrayList
listItem.add(map);
}
//Création d'un SimpleAdapter qui se chargera de mettre les items présents dans notre list(listItem) dans la vue SimpleAdapter
mSchedule = new SimpleAdapter (this, listItem,
R.layout.list,new String[] {"img", "titre"}, new int[] {R.id.img, R.id.titre});
//On attribue à notre listView l'adapter que l'on vient de créer
maListViewPerso.setAdapter(mSchedule);
Toast.makeText(this,"llllll"+ca.size(), Toast.LENGTH_LONG).show();
}
// boutton ajout
ajout=(Button)findViewById(R.id.ajt);
ajout.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent myIntent = new Intent(view.getContext(), Ajoutcam.class);
startActivityForResult(myIntent, 0);
}
});
// boutton supprimer
supp=(Button)findViewById(R.id.sup);
supp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
con.open2();
if(con.delete("camera", 4)!=-1)
{
Toast.makeText(Camlist.this,"hhhh", Toast.LENGTH_LONG).show();
// coment faire l'actualisation ???????
}
}
});
// boutton modifier
modif=(Button)findViewById(R.id.modif);
// boutton entrer
entre=(Button)findViewById(R.id.entre);
}
} |
Partager