Android: Change image on button click

This little android example will show you how to change the image of an image view trough a button click. For this we have two images in our drawable folder:
Unbenannt

 

We define an image view in activity_main.xml and two buttons for switching on/off the brain:

Now we need to implement the code in the MainActivity.java like this:

 

This is the main part changing the image:

 

Demo:
https://play.google.com/store/apps/details?id=mistcoder.com.brainon

Source download:

https://github.com/javaport/brainon

About The Author

Related posts

To post sourcecode please use <code>..</code> tags.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar