我正在尝试从 SQLite 数据库中检索图像路径并在 ImageView 上显示相应的图像。问题是,助手类没有返回图像名称,所以我无法在 ImageView 中显示图像。请参阅下面的 helper.class 代码
public static final String GETSD = "select DISTINCT FileName from Photos where
last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from Photos where
DisplayCount in (select MIN(DisplayCount) from Photos));";
public static final String UPDATE_DISP = "update Photos set DisplayCount =
Displaycount+1 where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp)
from Photos where DisplayCount in (select MIN(DisplayCount) from Photos));";
public static final String UPDATE_TIMESTAMP = "update Photos set
last_disp_TimeStamp = CURRENT_TIMESTAMP where FileName in (select FileName from
Photos where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from Photos
where DisplayCount in (select MIN(DisplayCount) from Photos)));";
public String getSDPath() {
// TODO Auto-generated method stub
Cursor c;
SQLiteDatabase myDB ;
String commonpath = "/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/";
String result="";
String h = "";
try {
myDB=this.openDataBase();
c=myDB.rawQuery(GETSD,null);
myDB.execSQL(UPDATE_DISP);
myDB.execSQL(UPDATE_TIMESTAMP);
if (c != null ) {
if (c.moveToFirst()) {
do {
// put your code to get data from cursor
int img = c.getColumnIndex("FileName");
result = c.getString(img);
h=commonpath+result;
final String imageFilePath = c.getString(img);
Log.v("IMAGE PATH====>>>> ", imageFilePath);
}while (c.moveToNext());
}
}
if(c != null)
{
myDB.close();
c.close();
}
}catch(SQLException sqle){
throw sqle;
}
return h;
}
查询工作正常,当我在 SQLite 浏览器上测试它们时,查询没有任何问题。我检查了文件/data/data/com.example.myappname/databases/
夹中的数据库文件。我有所需的照片/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/
。
此函数返回的路径是 /storage/sdcard/DCIM/Camera/SAMPLE IMAGES/。但是这个函数的预期字符串是 /storage/sdcard/DCIM/Camera/SAMPLE IMAGES/xxx.png
字符串“xxx.png”存储在数据库中,通过查询 GET_SD,我正在检索图像的名称。