How to select multiple images from gallery in android?

前端 未结 9 1886
無奈伤痛
無奈伤痛 2020-11-27 14:48

I am making a project in which i want to select multiple photos from gallery and want to save that in imageview array. I am able to import single image and save at imageview

9条回答
  •  甜味超标
    2020-11-27 15:18

    int SELECT_PICTURE=1;
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            switch (requestCode) {
                case SELECT_PICTURE:
                    Uri selectedImageUri = data.getData();
                    imgPerview.setBackgroundColor(Color.TRANSPARENT);
                    LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
                    imgPerview.setLayoutParams(vp);
                    imgPerview.setScaleType(ImageView.ScaleType.FIT_XY);
                    imgPerview.setImageURI(selectedImageUri);
                    uri = selectedImageUri;
            }
        }
        catch (Exception ex)
        {}
    }
    

提交回复
热议问题