I have an activity where you can upload 3 different pictures after clicking one of the 3 different buttons. You can only choose images one by one, as opposed to choosing 3 in one go. Each "button" is actually a clickable ImageView, which when clicked should prompt the user to choose a picture and then the picture they select should populate the ImageView that they clicked. I know how to work with just 1 imageView per activity so I'm currently stuck.
My thought process is as follows:
Have 3 different
Booleanvariables which are linked to 3 differentclickableImageViews.private var clickedView1: Boolean = false //same for the other viewsWhen 1 of the views is clicked(
OnClickListeners), toggle theBooleanlinked to it so that it's true.upload1.setOnClickListener { clickedView1 = true uploadPicture() } //same for the other viewsIf the boolean updates to true, populate the corresponding imageView (done in the onActivityResult).
if (clickedView1) { if (requestCode == 0 && resultCode == Activity.RESULT_OK && data != null) { selectedPhotoUri1 = data.data ImagesList?.plus(selectedPhotoUri1) val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, selectedPhotoUri1) upload1.setImageBitmap(bitmap) } } else if { //same thing for the other views }
In my head that makes sense, but I know it's wrong and when I program it and launch the activity, I have to be strategic RE the order I populate the image views (i.e. it only works from the last ImageView, going to the first). Any other order doesn't work and will always populate the first ImageView, no matter which is clicked.
Is there an efficient and accurate way of doing the population + OnClickListeners?