Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4599726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:34:55+00:00 2026-05-21T23:34:55+00:00

I have an Activity with three images. When one image is clicked, all the

  • 0

I have an “Activity” with three images. When one image is clicked, all the images are to switch to another picture. Is there a way to make the switches such that there is a 2 second delay before the images actually change (i.e. a 2 second delay in every ‘for loop’ below)? I am trying to do this with a timer but it does not actually to the delay when I run my program:

protected void onCreate(Bundle savedInstanceState) {
image1.setOnClickListener(this);

@Override
public void onClick(View arg0) 
{
do_switches();
}

private void do_switches() 
{
//loop through all images and change them
for(int j=1 ;j<=3; j++)
{           


 final int curr2=current;
 final Handler handler = new Handler(); 
 Timer t = new Timer(); 
 t.schedule(new TimerTask() { 
       public void run() { 
        handler.post(new Runnable() { 
               public void run() { 

        switch(curr2){

        case 1:

            image1.setImageResource(ImageArray[1]);
                    break;

        case 2:

            image2.setImageResource(ImageArray[2]);
                             break;

        case 3:
            image3.setImageResource(ImageArray[3]);
                        break;

        }
            } 
        }); 
    } 
 }, 2000); 
}

}

I have also tried using just SystemClock.sleep(2000) instead of the timer but I that didnt work either.I also tried setting up a Thread with a try/catch with no luck or maybe I didn’t implement it properly. Is there a way to put this delay on every iteration of my for loop?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:34:56+00:00Added an answer on May 21, 2026 at 11:34 pm

    Not one of best option, but still you can try CountDownTimer.

    http://developer.android.com/reference/android/os/CountDownTimer.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one tell me were i am going wrong. i have three activity's
I have button of pick image from android gallery in one activity name DrawingActivity.
I have an activity that launches another activity with startActivityForResult method. I would like
is there a way to get every view that is inside my activity? I
In one Android activity I have added a context menu to an ImageView with
I have an activity in which I display an image that is stored on
Is there any way to refer more than one widget (ui controls) by a
In my application there are two class one is InternetActivity which only extends Activity
I am using relative layout for one of my main activity with a image
I have an Android tab layout with three tabs, one of which has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.