This is fourth android application and this is same as third application but using only one button to change image here, so see third application and compare. Create new project and drag image view, one button view in relative layout and give id iv and bt respectively.
To change image on button click, we are calling a method in Java file but we have to declare this method in XML file, use this code in button tag :android:onClick=”method_name” and use same method name in Java file and pass view object in this method which will keep id of clicked button. The code of android xml file is give below:
Now open android Java file and use the same method which is declared in button tag in XML file. Use a Boolean flag to change the image. The code of android Java file is given below:
Comment to improve this code and share your ideas to make it better...