hey les gars, je peux actuellement récupérer des données de la base de données dans une table, mais je suis coincé avec listview. mon code est ceci pour récupérer toutes les données:Remplir listview à partir de la base de données
public ArrayList<Object> getRowAsArray(long rowID)
{
// create an array list to store data from the database row.
// I would recommend creating a JavaBean compliant object
// to store this data instead. That way you can ensure
// data types are correct.
ArrayList<Object> rowArray = new ArrayList<Object>();
Cursor cursor;
try
{
// this is a database call that creates a "cursor" object.
// the cursor object store the information collected from the
// database and is used to iterate through the data.
cursor = db.query
(
TABLE_NAME,
new String[] { TABLE_ROW_ID, TABLE_ROW_ONE, TABLE_ROW_TWO, TABLE_ROW_THREE, TABLE_ROW_FOUR, TABLE_ROW_FIVE, TABLE_ROW_SIX, TABLE_ROW_SEVEN },
TABLE_ROW_ID + "=" + rowID,
null, null, null, null, null
);
// move the pointer to position zero in the cursor.
cursor.moveToFirst();
// if there is data available after the cursor's pointer, add
// it to the ArrayList that will be returned by the method.
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getLong(0));
rowArray.add(cursor.getString(1));
rowArray.add(cursor.getString(2));
rowArray.add(cursor.getString(3));
rowArray.add(cursor.getString(4));
rowArray.add(cursor.getString(5));
rowArray.add(cursor.getString(6));
rowArray.add(cursor.getString(7));
}
while (cursor.moveToNext());
}
// let java know that you are through with the cursor.
cursor.close();
}
catch (SQLException e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
// return the ArrayList containing the given row from the database.
return rowArray;
}
comment pourrais-je remplir ce dans un listview s'il vous plaît. toute aide appréciée
Vous connaissez un tutoriel. Je me suis débrouillé mais aucun au type dont j'avais besoin. J'ai 7 lignes dans la base de données pour montrer – Fizzb89
Les démos d'API sont très clairement structurées. Il y a un groupe pour "Listes", et il y en a un pour "données du curseur". Juste ici: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html – EboMike
merci mon pote. Je viens de jeter un oeil maintenant, ils semblent l'utiliser pour uris. Curseur curseur = managedQuery (getIntent(). GetData(), PROJECTION, null, null, NoteColumns.DEFAULT_SORT_ORDER); // Utilisé pour mapper les entrées de la base de données aux vues SimpleCursorAdapter adapter = new SimpleCursorAdapter (this, R.layout.noteslist_item, curseur, new String [] {NoteColumns.TITLE}, nouvel int [] {android.R .id.text1}); setListAdapter (adaptateur); comment le mien serait lié à cela. merci compagnon – Fizzb89