从sdcard获取基于sqlite文件名的图像并在gridview中显示

时间:2016-07-17 02:58:09

标签: android sqlite gridview

尝试从sdcard获取图像并在gridview中显示,来自sqlite的数据图像文件名。在显示之前我想检查图像文件名存在于sqlite

以下是我到目前为止所获得的代码: -

/ ******* ****** SQLITE /

    String selectQuery = "SELECT " + KEY_IMGNAME + " FROM " + TABLE_PLANTASKIMG + " WHERE project_planner_task_id='" + plantaskid + "'";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();
    ArrayList<String> names = new ArrayList<String>();
    while(!cursor.isAfterLast()) {
        names.add(cursor.getString(cursor.getColumnIndex(KEY_IMGNAME)));
        cursor.moveToNext();
    }
    cursor.close();
    return names.toArray(new String[names.size()]);

/ ****结束sqlite **** /

file_name_in_db = db.getImgTask(pptaskid);listFile = file.listFiles();
        // Create a String array for FilePathStrings
        FilePathStrings = new String[listFile.length];
        // Create a String array for FileNameStrings
        FileNameStrings = new String[listFile.length];

        for (int i = 0; i < listFile.length; i++) {


            for(int j=0; j<file_name_in_db.length;i++){
                if(file_name_in_db[j].equals(FileNameStrings[i])){

          // Get the path of the image file
            FilePathStrings[i] = listFile[i].getAbsolutePath();
            Log.d(TAG,"filepathstring:"+FilePathStrings);
            // Get the name image file
            FileNameStrings[i] = listFile[i].getName();
            Log.d(TAG,"FileNameStrings:"+FileNameStrings);

                }
            }
        }
gridView = (GridView) findViewById(R.id.gridView);gridAdapter = new GridViewAdapter(this, FilePathStrings, file_name_in_db);
    // Set the LazyAdapter to the GridView
    gridView.setAdapter(gridAdapter);

我的问题是上面的代码不能用于检查来自sqlite的带有图像文件名的sql中的图像文件名。

0 个答案:

没有答案