2010-09-20 6 views
-1

J'ai ce code dans mon DataBase Helper:SQLite à ListActivity

public ArrayList<ArrayList<Object>> getAllRowsAsArrays() 
{ 
    // create an ArrayList that will hold all of the data collected from 
    // the database. 
    ArrayList<ArrayList<Object>> dataArrays = new ArrayList<ArrayList<Object>>(); 

    // 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 cursor; 

    try 
    { 
     // ask the database object to create the cursor. 
     cursor = db.query(
       TABLE_NAME, 
       new String[]{TABLE_ROW_NAME}, 
       null, null, null, null, null 
     ); 

     // move the cursor's pointer to position zero. 
     cursor.moveToFirst(); 

     // if there is data after the current cursor position, add it 
     // to the ArrayList. 
     if (!cursor.isAfterLast()) 
     { 
      do 
      { 
       ArrayList<Object> dataList = new ArrayList<Object>(); 

       dataList.add(cursor.getString(1)); 

       dataArrays.add(dataList); 
      } 
      // move the cursor's pointer up one position. 
      while (cursor.moveToNext()); 
     } 
    } 
    catch (SQLException e) 
    { 
     Log.e("DB Error", e.toString()); 
     e.printStackTrace(); 
    } 

    // return the ArrayList that holds the data collected from 
    // the database. 
    return dataArrays; 
} 

Comment puis-je utiliser ce code et afficher les résultats dans un ListActivity?

Vous en avez été bloqué pendant les 2 derniers jours. Toute aide à ce sujet est appréciée.

Merci d'avance.

Répondre

Questions connexes