title: How can i pick a image from gallery?
body: <p>I am making a project in which in which i am using two <code>ImageView</code>s and i want to pick two different images from <code>gallery</code> and i want to set on two different <code>ImageView</code>s. I am able to pick one and set on one <code>imageview</code>. but i am not coming to understand that how i can do this in second <code>imageview</code> case?</p>
  
  <p>The code i used is...</p>
  
  <pre><code>ImageView iv1,iv2;
  
      private static int RESULT_LOAD_IMAGE = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
  
  
              setContentView(R.layout.layout2);
  
          iv1=(ImageView)findViewById(R.id.imageView21);
          iv1.setOnClickListener(this);
          iv2=(ImageView)findViewById(R.id.imageView21);
          iv2.setOnClickListener(this);
  
      }
  
  @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
          if(v.getId()==R.id.imageView21){
              Intent i = new Intent(
                      Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
              startActivityForResult(i, RESULT_LOAD_IMAGE);
          }
              }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
              Uri selectedImage = data.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String picturePath = cursor.getString(columnIndex);
              cursor.close();
  
  
              iv1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
          }
  
  
      }
  </code></pre>
  
  <hr>
  
  <p>Update 1...</p>
  
  <p>It is giving problem, it is settingup image on both imageview even if i am trying to do for one...</p>
  
  <pre><code>public class LayoutDisplay2 extends Activity{
  
      ImageView iv1, iv2;
      private static int RESULT_LOAD_IMAGE1 = 1;
      private static int RESULT_LOAD_IMAGE2 = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
  
  
          setContentView(R.layout.layout2);
  
          iv1 = (ImageView) findViewById(R.id.imageView21);
          iv1.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent i = new Intent(
                          Intent.ACTION_PICK,
                          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
                  startActivityForResult(i, RESULT_LOAD_IMAGE1);
              }
          });
          iv2 = (ImageView) findViewById(R.id.imageView22);
          iv2.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
  
                  Intent in = new Intent(
                          Intent.ACTION_PICK,
                          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
                  startActivityForResult(in, RESULT_LOAD_IMAGE2);
              }
          });
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RESULT_LOAD_IMAGE1 &amp;&amp; resultCode == RESULT_OK
                  &amp;&amp; null != data) {
              Uri selectedImage = data.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String picturePath = cursor.getString(columnIndex);
              cursor.close();
  
              iv1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
          }
          if (requestCode == RESULT_LOAD_IMAGE2 &amp;&amp; resultCode == RESULT_OK
                  &amp;&amp; null != data) {
              Uri selectedImage = data.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
              Toast.makeText(getApplicationContext(), "in second",
                      Toast.LENGTH_SHORT).show();
              Log.i("Second", "in second");
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String picturePath = cursor.getString(columnIndex);
              cursor.close();
  
              iv2.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
          }
  
      }
  
  }
  </code></pre>