I have an Android App that uses a database. The db class I created will iterate the database and use a seperate class to ?"HOLD"? each row.
public List<Poster> getAllPosters() {
List<Poster> posterList = new ArrayList<Poster>();
// Select All Query
String selectQuery = "SELECT * FROM " + "posters";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Poster poster = new Poster(Integer.parseInt(cursor.getString(0)),Integer.parseInt(cursor.getString(1)),Integer.parseInt(cursor.getString(2)),cursor.getString(3),cursor.getString(4),cursor.getString(5),cursor.getString(6),cursor.getString(7),cursor.getString(8));
// Adding contact to list
posterList.add(poster);
} while (cursor.moveToNext());
}
db.close(); // Closing database connection
// return contact list
return posterList;
}
The Poster Class is as you would expect. It has a constructor with each variable that relates to a column and a method to set and get each column value.
So is each row now it's own object that can be accessed anytime or is it the Poster Class that is the object and it contains all of the rows?
Also, is this object in memory until the app terminates or is overwritten by a new instance of Poster?