0
我有可繪製的圖像和具有列名稱的數據庫,如price和imageName ...所以我想檢索所有imageNames列表並顯示與數據庫中的其他領域......所以在這裏我已經嘗試了現在一個ListView對應的圖像一起..如何從包括圖像規格的可繪製圖像檢索圖像並將其顯示到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;
}
你能給我舉個例子怎麼做 – user1430923