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
| package com.example.sqlitedatabase;
import android.os.Bundle;
import android.app.Activity;
import android.widget.ListView;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;
public class voirListeDB extends Activity{
SQLiteDataBaseHelper db; // déclaration de l'objet db
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maliste);
db = new SQLiteDataBaseHelper(this);
//**********************************essai garder tout*****************************************
// Définition des colonnes
// NB : SimpleCursorAdapter a besoin obligatoirement d'un ID nommé "_id"
String[] columns = new String[] { "_id", "col1", "col2", "col3", "col4", "col5" };
// on prendra les données des colonnes 1 à 5..
String[] from = new String[] {"col1", "col2", "col3", "col4","col5"};
// ...pour les placer dans les TextView définis dans "row_item.xml"
int[] to = new int[] { R.id.textViewCol1, R.id.textViewCol2,R.id.textViewCol3,R.id.textViewCol4, R.id.textViewCol5};
//*******************************fin essai garder tout****************************************************************
ListView lv = this.findViewById(R.id.maliste);
//appel de la méthode crerColonne
Cursor data = db.crerColonne();//appel de la méthode pour obtenir l'allias _id
// création de l'objet SimpleCursorAdapter...
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row_item, data,new String []
{"TYPE", "NOM", "ETAT", "NOMBRE","ENDROIT"}, new int[] {R.id.textViewCol1, R.id.textViewCol2,
R.id.textViewCol3, R.id.textViewCol4, R.id.textViewCol5});
lv.setAdapter(adapter);
} //fin de onCreate
} //fin de la classe voirListeDB |
Partager