drawable に画像があり、price や imageName などの列名を持つデータベースがあります...したがって、imageNames のすべてのリストを取得し、対応する画像をデータベース内の他のフィールドと一緒に listView に表示したい...ここで何を私は今試してみました..
//getting a list of names from database
public List<String> populateList(){
List<String> ItemsList = new ArrayList<String>();
DatabaseHelper openHelper = new DatabaseHelper(this);
SQLiteDatabase sqliteDatabase = openHelper.getReadableDatabase();
// We need a a guy to read the database query. Cursor interface will do it for us
//(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
Cursor cursor = sqliteDatabase.query(DBAdapter.ITEMS_TABLE, null, null, null, null, null, null);
// Above given query, read all the columns and fields of the table
startManagingCursor(cursor);
while (cursor.moveToNext()) {
// In one loop, cursor read one undergraduate all details
// Assume, we also need to see all the details of each and every undergraduate
// What we have to do is in each loop, read all the values, pass them to the POJO class
//and create a ArrayList of undergraduates
String BName = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_NAME));
String Bauthor = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_AUTHOR));
String Bgenre = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_GENRE));
String Bpublisher = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_PUBLISHER));
String Bcover = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_COVER_TYPE));
int Bpages = cursor.getInt(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_NUM_PAGES));
int Bage = cursor.getInt(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_AGE_RESTRICTION));
int Bqty = cursor.getInt(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_QUANTITY));
double Bprice = cursor.getDouble(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_PRICE));
String Bimage = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_BOOK_IMAGE));
//String uHaddress = cursor.getString(cursor.getColumnIndex(DBAdapter.COLUMN_ADDRESS));
//double ugGpa = cursor.getDouble(cursor.getColumnIndex(AndroidOpenDbHelper.COLLUMN_NAME_UNDERGRADUATE_GPA));
// Finish reading one raw, now we have to pass them to the POJO
BooksPojo uPojoClass = new BooksPojo(BName, Bauthor, Bgenre, Bpublisher, Bcover, Bpages, Bage, Bqty, Bprice, Bimage);
// Lets pass that POJO to our ArrayList which contains undergraduates as type
pojoArrayList.add(uPojoClass);
// But we need a List of String to display in the ListView also.
//That is why we create "uGraduateNamesList"
ItemsList.add(Bimage);
}
// If you don't close the database, you will get an error
sqliteDatabase.close();
return ItemsList;
}