I have 2 buttons:
- on 1 button I can take pictures
- on the other button I can select pictures from the gallery.
The problem is when I take a picture it is displaying it, but when I take a another picture it is replacing the current picture, but what I want is that the pictures comes underneath each other. So for example I select 1 picture from the gallery and I take 2 pictures, I want to see 3 pictures but I can't find the right solution to it.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCamera = findViewById(R.id.btnCamera);
imageView = (ImageView)findViewById(R.id.imageView);
btnTakeImg = (Button)findViewById(R.id.btnTakeImg);
// Open camera and take picture
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
// Pick image from gallery
btnTakeImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openGallery();
}
});
}
private void openGallery() {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
imageUri = data.getData();
imageView.setImageURI(imageUri);
}
if(resultCode == RESULT_OK && requestCode == 0) {
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}