2011-03-25 113 views
0

在我的畫廊我有3個目錄。 sahoo是其中的一個目錄。我在所有三個目錄中都有不同的圖像。但我只想顯示sahoo目錄的圖像。我的程序顯示了圖庫中的所有圖像。但我只想從sahoo目錄中獲取圖像。怎麼做? 我正在使用android。如何顯示來自特定目錄的圖像,android

感謝 迪帕克

我用下面的代碼

Uri uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI; 
Cursor mCursor = this.getContentResolver().query(uri, null, selection, null, null); 

和getview方法我已經寫了下面的代碼行

mCursor.moveToPosition(position); 
     Log.e(TAG,"the position is"+position); 
     long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID)); 
//  Log.e(TAG,"the value of id= "+id); 
     //create the Uri for the Image 
     Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id+""); 

     Intent intent = new Intent(Intent.ACTION_VIEW); 

     intent.setData(uri); 

     startActivity(intent); 
+0

是你sahoo目錄庫的子目錄? – RoflcoptrException 2011-03-25 07:59:59

+0

能完成這項工作嗎? http://stackoverflow.com/questions/3490623/is-there-any-way-to-look-for-an-image-using-the-path-mediastore-images-thumbnail – rajath 2011-03-25 08:04:20

+0

是的,它的工作原理。 sahoo目錄是庫的子目錄 – 2011-03-25 09:14:17

回答

0

你可以從所有圖像的路徑使用遊標。然後檢查路徑是否與您不想顯示圖像的路徑不匹配,然後存儲pathin arraylist。使用setImageURI()方法在ImageView中創建您的owngrid和適配器顯示圖像。在這種情況下,Donot使用默認畫廊。

uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 

      String[] projection = { MediaColumns.DATA, 
        MediaColumns.DISPLAY_NAME }; 

      cursor = activity.managedQuery(uri, projection, null, null, null); 
      column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); 
while (cursor.moveToNext()) { 
String absolutePathOfImage = cursor.getString(column_index); 
} 

感謝 蘇尼爾

相關問題