Search code examples
androidperformanceandroid-cameraandroid-imageviewimage-gallery

How to upload particular image on particular imageView click from gallery and camera in android


i have 4 diffrent imageview and try to click on all to upload diffrent images like LIcence,Rc,Profile etc . I want to uploaded image from gallery or camera dialog.. like this layout. like uper layout example


Solution

  • Please check my updated answer. This is just an example. Hope you understand from this

      ImageView profile_pic;
        private static final int SELECT_PICTURE1 = 100;
        private static final int SELECT_PICTURE2 = 101;
        private static final int SELECT_PICTURE3 = 102;
        private static final int SELECT_PICTURE4 = 103;
    
    
    
    
    
    picture1 = (ImageView) view.findViewById(R.id.picture1);
    picture2 = (ImageView) view.findViewById(R.id.picture2);
    picture3 = (ImageView) view.findViewById(R.id.picture3);
    picture4 = (ImageView) view.findViewById(R.id.picture4);
    picture1.setOnClickListener(this);
    picture2.setOnClickListener(this);
    picture3.setOnClickListener(this);
    picture4.setOnClickListener(this);
    
    
    
    
    
    
    
    @Override
        public void onClick(View v) {
            if (v.getId() == R.id.picture1) {
                 Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE1);
            }
    
             if (v.getId() == R.id.picture2) {
                 Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE2);
            }
             if (v.getId() == R.id.picture3) {
                 Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE3);
            }
    
             if (v.getId() == R.id.picture4) {
                 Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE4);
            }
    
    
        }
    
    
    
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE1) {
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    String path = selectedImageUri.getPath();
                    Log.e("image path", path + "");
                    pricture1.setImageURI(selectedImageUri);
                }
            } 
    
            if (requestCode == SELECT_PICTURE2) {
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    String path = selectedImageUri.getPath();
                    Log.e("image path", path + "");
                    picture2.setImageURI(selectedImageUri);
                }
            } 
    
            if (requestCode == SELECT_PICTURE3) {
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    String path = selectedImageUri.getPath();
                    Log.e("image path", path + "");
                    picture3.setImageURI(selectedImageUri);
                }
            } 
    
            if (requestCode == SELECT_PICTURE4) {
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    String path = selectedImageUri.getPath();
                    Log.e("image path", path + "");
                    picture4.setImageURI(selectedImageUri);
                }
            } 
        }
    }