2017-12-05 15 views
-1
ImageView imageView = (ImageView) findViewById(R.id.Gallery); 
    imageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent galleryIntent = new Intent(Intent.ACTION_PICK, 
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
      // Start the Intent 
      startActivityForResult(galleryIntent, RESULT_LOAD); 

     } 
    }); 

} 
    @Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    // When an Image is picked 
    if (requestCode == RESULT_LOAD && resultCode == RESULT_OK 
      && null != data) { 
     // Get the Image from data 

     Uri imageUri = data.getData(); 
     InputStream imageStream = null; 
     try { 
      imageStream = getContentResolver().openInputStream(imageUri); 
      ImageView imageView = (ImageView) findViewById(R.id.Gallery); 
      imageView.setImageBitmap(BitmapFactory.decodeStream(imageStream)); 
     } catch (FileNotFoundException e) { 
      // Handle the error 
     } finally { 
      if (imageStream != null) { 
       try { 
        imageStream.close(); 
       } catch (IOException e) { 
        // Ignore the exception 
       } 
      } 
     } 
    } 

} 

このコードは1つのimageViewに追加して画像を表示する場合に問題ありません。どのように私はそれが一度だけ画像を選択する代わりに、すべてのImageViewのギャラリーから1画像を選択して複数のImageViewに表示

+0

フォームギャラリー一度に複数の写真を選択しますか?または単一の画像。それを明確にしなさい。 – ADM

+0

あなたは正しく読むことを理解していません –

+1

私はそれを読んでいます。それは私が尋ねた理由です。問題は私には分かりません。今は[Duplicate](https://stackoverflow.com/questions/23426113/how-to-select-multiple-images-from-gallery-in-android)のようです。 – ADM

答えて

0

は、このようなコード実行します。ここで

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
super.onActivityResult(requestCode, resultCode, data); 
// When an Image is picked 
if (requestCode == RESULT_LOAD && resultCode == RESULT_OK 
     && null != data) { 
    // Get the Image from data 

    Uri imageUri = data.getData(); 
    InputStream imageStream = null; 
    try { 
     imageStream = getContentResolver().openInputStream(imageUri); 
     ImageView imageView = (ImageView) findViewById(R.id.Gallery); 

    imageView.setImageBitmap(BitmapFactory.decodeStream(imageStream)); 
    imageView1.setImageBitmap(BitmapFactory.decodeStream(imageStream)); 
    imageView2.setImageBitmap(BitmapFactory.decodeStream(imageStream)); 
    imageView3.setImageBitmap(BitmapFactory.decodeStream(imageStream)); 
    } catch (FileNotFoundException e) { 
     // Handle the error 
    } finally { 
     if (imageStream != null) { 
      try { 
       imageStream.close(); 
      } catch (IOException e) { 
       // Ignore the exception 
      } 
     } 
    } 
} 

を、ImageViewの、imageView1、imageView2、imageView3は異なる画像ビューのインスタンスです。

ありがとうございました&もっと助けが必要な場合は教えてください!

EDITED:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
super.onActivityResult(requestCode, resultCode, data); 
// When an Image is picked 
if (requestCode == RESULT_LOAD && resultCode == RESULT_OK 
    && null != data) { 
    // Get the Image from data 

    Uri imageUri = data.getData(); 
    InputStream imageStream = null; 
    try { 
    imageStream = getContentResolver().openInputStream(imageUri); 
    Bitmap bitmap = BitmapFactory.decodeStream(imageStream); 


      imageView.setImageBitmap(bitmap); 
      imageView1.setImageBitmap(bitmap); 
      imageView2.setImageBitmap(bitmap); 
      imageView3.setImageBitmap(bitmap); 
} catch (FileNotFoundException e) { 
    // Handle the error 
} finally { 
    if (imageStream != null) { 
     try { 
      imageStream.close(); 
     } catch (IOException e) { 
      // Ignore the exception 
     } 
    } 
} 

}

EDITED第二:

public class ThirdJavaActivity extends Activity { 

ImageView imageView,imageView1,imageView2,imageView3; 

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.content_third); 

    imageView = (ImageView)findViewById(R.id.imageView); 
    imageView1 = (ImageView)findViewById(R.id.imageView1); 
    imageView2 = (ImageView)findViewById(R.id.imageView2); 
    imageView3 = (ImageView)findViewById(R.id.imageView3); 

    Intent galleryIntent = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    // Start the Intent 
    startActivityForResult(galleryIntent, 101); 

} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
// When an Image is picked 
    if (requestCode == 101 && resultCode == RESULT_OK 
      && null != data) { 
     // Get the Image from data 

     Uri imageUri = data.getData(); 
     InputStream imageStream = null; 
     try { 
      imageStream = getContentResolver().openInputStream(imageUri); 

      Bitmap bitmap = BitmapFactory.decodeStream(imageStream); 

      imageView.setImageBitmap(bitmap); 
      imageView1.setImageBitmap(bitmap); 
      imageView2.setImageBitmap(bitmap); 
      imageView3.setImageBitmap(bitmap); 
     } catch (Exception e) { 
      // Handle the error 
     } finally { 
      if (imageStream != null) { 
       try { 
        imageStream.close(); 
       } catch (IOException e) { 
        // Ignore the exception 
       } 
      } 
     } 
    } 
} 
} 
+0

あなたはこのコードを自分で試しませんでしたか?あなたはそれが動作しないことを発見したでしょう。 – greenapps

+0

私の編集した答えを試してください –

+0

あなたの編集された答えは私の答えと同じです。恥を知れ! – greenapps

0
How can i get it to be displayed in multiple imageViews by just selecting an image 

するためのプロセスを繰り返すことによって、複数のimageViewsに表示されるように得ることができることは、ストリームからBitmapを作成します。

次に、必要なイメージビューにビットマップを割り当てます。

関連する問題