Recent Posts

Site Creator

Day 8 : Image flipping Problem in Android

Posted on

Dear Friends

Today we have a challenge to solve where we need to show an Image in Android UX and this image will be switched to different image after few seconds.  Something similar to changing wallpaper functionality.

Solution

Friends I have created another blog post that will help beginners to setup a new android project in android studio. Please visit [link] and after reading the page kindly come back to this blog post to continue solving problem. visit

Coming back to our original problem

Lets have an Activity A which can show Image in UX (view).

A simple code snippet that assumes Imageview in layout.xml file. Although we can generate a imageview dynamically via java code but we keep this for some other blog post. For simplicity we are inflating image view via xml using findviewById

So in the above code snippet imageview is inflated from xml and then an image is set inside image view.

lets add two buttons below imageview

My Beginner friends please visit link to understand xml attributes used above. [Link would be updated]

I am keeping this blog simple so users can skip links.

Now please add references to your buttons means binding your java code with xml.

So now your java code for Mainactivity would becomes like below

Now please run your application in device.

you will get output as snapshotoutput

Now add onclickhandler for our two buttons add in oncreate method

What if we want different images to be shown on click of buttons. ?

Lets create one image array .

create one instance variable count for image array index.

int count = 0;

so in onclick handlers for buttons will be edited as below

So you now know how to make a very simple image switching. For Image Flipper advance dev please visit my another blog post. [ Link]

Thanks for reading.







Disclaimer: The aforesaid writeup by Relsell Global writer is for the general understanding of the readers. It does not render any professional advice or opinion.

SHARE THIS PAGE!