I am new to Android development. I'm doing it with Kotlin. I got an assignment to change the imageView image using OnLongClickListener like changing two to three images every long press. also, I want to save the state of the images after the rotating screen. I set it up for changing one image to another for one time but still confused how to do it properly.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
lightMe.setOnLongClickListener {
lightMe.run {
lightMe.setImageDrawable(getDrawable(R.drawable.ic_baseline_flare_24))
lightMe.setImageDrawable(getDrawable(R.drawable.ic_baseline_wb_incandescent_24))
true
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
}
Check this example. I have added one
ImageViewand I am changing the image on a long click.MainActivity.kt:
main_activity.xml (just an image):