我想從遊標返回的Uri(在一個SQLite數據庫列)設置imageView,但它不工作。從光標設置imageView
代碼:
mCursor = mydb.rawQuery("select * from events;", null);
if (mCursor != null) {
mCursor.moveToFirst();
String[] from = new String[]{DbHandler.column_id, DbHandler.column_name, DbHandler.column_location, DbHandler.column_date, DbHandler.img_loc};
int[] to = new int[] {R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.photoInDb};
SimpleCursorAdapter simpleCurs = new SimpleCursorAdapter(this, R.layout.listviewfinal, mCursor, from, to);
simpleCurs.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int i) {
if (view instanceof ImageView) {
ImageView image = (ImageView) view;
// just to see what is returned by this!
Log.d("orange", "images: " + cursor.getString(i));
Bitmap thumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(cursor.getString(i)), 320, 240);
image.setImageBitmap(thumbImage);
return true;
}
return false;
}
});
listView.setAdapter(simpleCurs);
什麼想法?
你是ge來自數據庫的圖像網址? –
是的。有一列有照片的Uri保存在SD卡上。 Log.d行返回「images:file:///storage/sdcard0/DCIM/OrangeClubPhotos/1370853592867.jpg」 - 並且文件存在。所以問題在於它沒有在圖像視圖中設置文件。 – kevoroid