2011-10-21 3 views

答えて

1

複数の画像ファイルを選択するには、チェックボックスを持つ独自の画像リストを作成する必要があります。

次のコードを使用してギャラリーのカーソルを取得し、カーソルを反復してイメージを表示するリストアダプターを作成します。この画像を使用して、チェックボックスでリストビューで表示することができます。ここから

String[] projection = { MediaStore.Images.Media.DATA }; 
Cursor cursor = managedQuery(uri, projection, null, null, null); 
+0

ok、ギャラリー内のすべての画像を取得する方法...? – Noby

+0

このためには、イメージURIを取得し、そのURIのカーソル用のアダプタを作成し、イメージのリストビューを作成する必要があります。これを参照してください:http://coderzheaven.com/2011/03/select-an-image-from-gallery-in-android-and-show-it-in-an-imageview/ –

+0

私たちは選択のためのギャラリー、一度に1つだけ。 – Noby

0

ダウンロードソースコード(Get all images from gallery in android programmatically

public ArrayList<Model_images> fn_imagespath() { 
     al_images.clear(); 

     int int_position = 0; 
     Uri uri; 
     Cursor cursor; 
     int column_index_data, column_index_folder_name; 

     String absolutePathOfImage = null; 
     uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 

     String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME}; 

     final String orderBy = MediaStore.Images.Media.DATE_TAKEN; 
     cursor = getApplicationContext().getContentResolver().query(uri, projection, null, null, orderBy + " DESC"); 

     column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); 
     column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); 
     while (cursor.moveToNext()) { 
      absolutePathOfImage = cursor.getString(column_index_data); 
      Log.e("Column", absolutePathOfImage); 
      Log.e("Folder", cursor.getString(column_index_folder_name)); 

      for (int i = 0; i < al_images.size(); i++) { 
       if (al_images.get(i).getStr_folder().equals(cursor.getString(column_index_folder_name))) { 
        boolean_folder = true; 
        int_position = i; 
        break; 
       } else { 
        boolean_folder = false; 
       } 
      } 


      if (boolean_folder) { 

       ArrayList<String> al_path = new ArrayList<>(); 
       al_path.addAll(al_images.get(int_position).getAl_imagepath()); 
       al_path.add(absolutePathOfImage); 
       al_images.get(int_position).setAl_imagepath(al_path); 

      } else { 
       ArrayList<String> al_path = new ArrayList<>(); 
       al_path.add(absolutePathOfImage); 
       Model_images obj_model = new Model_images(); 
       obj_model.setStr_folder(cursor.getString(column_index_folder_name)); 
       obj_model.setAl_imagepath(al_path); 

       al_images.add(obj_model); 


      } 


     } 


     for (int i = 0; i < al_images.size(); i++) { 
      Log.e("FOLDER", al_images.get(i).getStr_folder()); 
      for (int j = 0; j < al_images.get(i).getAl_imagepath().size(); j++) { 
       Log.e("FILE", al_images.get(i).getAl_imagepath().get(j)); 
      } 
     } 
     obj_adapter = new Adapter_PhotosFolder(getApplicationContext(),al_images); 
     gv_folder.setAdapter(obj_adapter); 
     return al_images; 
    } 

ありがとう!

関連する問題