title: How to upload multiple images in multiple buttons in android
body: <p>I have two buttons and two imageview. When I click on first button, it opens and uploads image.How to do for second button click and load image. My code is as follows</p>
  
  <pre><code>private static final int PICK_IMAGE = 1;
  upload1=(Button)findViewById(R.id.uploadimage1);
  upload2=(Button)findViewById(R.id.uploadimage2);
  imgView1=(ImageView)findViewById(R.id.image1);
  imgView2=(ImageView)findViewById(R.id.image2);
  upload1.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
               try {
                   Intent intent = new Intent();
                   intent.setType("image/*");
                   intent.setAction(Intent.ACTION_GET_CONTENT);
                   startActivityForResult(
                           Intent.createChooser(intent, "Select Picture"),
                           PICK_IMAGE);
               } catch (Exception e) {
                   Toast.makeText(getApplicationContext(),
                           "No image found", Toast.LENGTH_LONG).show();
                   Log.e(e.getClass().getName(), e.getMessage(), e);
  
          }
          }
      });
  
   @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          switch (requestCode) {
          case PICK_IMAGE:
              if (resultCode == Activity.RESULT_OK) {
                  Uri selectedImageUri = data.getData();
                  String filePath = null;
  
                  try {
                      // OI FILE Manager
                      String filemanagerstring = selectedImageUri.getPath();
  
                      // MEDIA GALLERY
                      String selectedImagePath = getPath(selectedImageUri);
  
                      if (selectedImagePath != null) {
                          filePath = selectedImagePath;
                      } else if (filemanagerstring != null) {
                          filePath = filemanagerstring;
                      } else {
                          Toast.makeText(getApplicationContext(), "Unknown path",
                                  Toast.LENGTH_LONG).show();
                          Log.e("Bitmap", "Unknown path");
                      }
  
                      if (filePath != null) {
                          decodeFile(filePath);
                      } else {
                          bitmap = null;
                      }
                  } catch (Exception e) {
                      Toast.makeText(getApplicationContext(), "Internal error",
                              Toast.LENGTH_LONG).show();
                      Log.e(e.getClass().getName(), e.getMessage(), e);
                  }
              }
              break;
          default:
          }
      }
      public String getPath(Uri uri) {
          String[] projection = { MediaStore.Images.Media.DATA };
          Cursor cursor = managedQuery(uri, projection, null, null, null);
          if (cursor != null) {
              // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
              // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
              int column_index = cursor
                      .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
              cursor.moveToFirst();
              return cursor.getString(column_index);
          } else
              return null;
      }
      public void decodeFile(String filePath) {
          // Decode image size
          BitmapFactory.Options o = new BitmapFactory.Options();
          o.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(filePath, o);
  
          // The new size we want to scale to
          final int REQUIRED_SIZE = 1024;
  
          // Find the correct scale value. It should be the power of 2.
          int width_tmp = o.outWidth, height_tmp = o.outHeight;
          int scale = 1;
          while (true) {
              if (width_tmp &lt; REQUIRED_SIZE &amp;&amp; height_tmp &lt; REQUIRED_SIZE)
                  break;
              width_tmp /= 2;
              height_tmp /= 2;
              scale *= 2;
          }
  
          // Decode with inSampleSize
          BitmapFactory.Options o2 = new BitmapFactory.Options();
          o2.inSampleSize = scale;
          bitmap = BitmapFactory.decodeFile(filePath, o2);
                      //first image i have uploaded by using first button
          imgView1.setImageBitmap(bitmap);
  
  
      }
  </code></pre>
  
  <p>Now my question is for second button how to upload in second image. Please help me to  solve this issue. Thanks in advance</p>