I have two imageViews in my app and I have two buttons. Each Button will change one of the ImageViews with a Gallery Picker.
However I don't know how to choose the image for each of the imageViews seperatly.
lateinit var frontImageView: ImageView
lateinit var backImageView: ImageView
private val pickImage = 100
private var imageUri: Uri? = null
...
override fun onCreate(savedInstanceState: Bundle?) {
frontImageView = findViewById(R.id.cb_image_frontside)
backImageView = findViewById(R.id.cb_image_backside)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK && requestCode == pickImage) {
imageUri = data?.data
frontImageView.setImageURI(imageUri) // This will just change the image for "frontImageView"
// But I can only always have one of the
// imageViews changed at one time
// How can I change the Image of "backImageView" with
// the other button?
}
}
// This is the fuction for the buttons
fun pickMedia(view: View) {
val gallery = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
startActivityForResult(gallery, pickImage)
}