【问题标题】:how to display images from a particular directory, android如何显示来自特定目录的图像,android
【发布时间】:2011-03-25 07:58:03
【问题描述】:

在我的画廊中,我有 3 个目录。 sahoo 是目录之一。我在所有三个目录中都有不同的图像。但我只想显示 sahoo 目录的图像。我的程序显示了画廊中存在的所有图像。但我只想从 sahoo 目录中获取图像。怎么做? 我用的是安卓。

谢谢 迪帕克

我使用了以下代码

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); 

【问题讨论】:

标签: android


【解决方案1】:

您可以使用光标获取所有图像的路径。然后检查路径是否与您不想显示图像的路径不匹配,然后将路径存储在数组列表中。使用 setImageURI() 方法在 ImageView 中创建自己的网格和适配器显示图像。在这种情况下不要使用默认图库。

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);
}

谢谢 苏尼尔

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2021-10-05
    相关资源
    最近更新 更多