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 9251703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:46:06+00:00 2026-06-18T10:46:06+00:00

I know that this is a very small question. But I can’t figure out

  • 0

I know that this is a very small question. But I can’t figure out the reason for this. In my program I run a loop 50 times. Inside the loop I generate a random integer 0 to 5 and load an image(a dice image) to a imageView. So imageView should change rapidly and I should be able to see some visual like dice value is changing rapidly.

But I couldn’t see any such change in imageView and at end of the loop, imageView changes at once.I mean if initial dice value is 2 it remains in two until loop finishes and then imageView suddenly change to 5 or some value like that.

I realized that I can’t see a change in dice imageView since loop is executing very fast. Then after going through Loop execution speed control I put Thread.sleep method but still there is not a change.

This is my code:

ImageView dice = (ImageView) findViewById(R.id.imageViewrollingdiceOne);
for (int i=0;i<50;i++){
        int randomNum = random.nextInt(6);
        System.out.println("Random Value"+randomNum);
        dice.setImageResource(images[randomNum]);
        try {
            Thread.sleep(200);
        } catch (Exception e) {
            System.out.println("ex called");
        }
    }

Can somebody explain the reason for this? I’m not getting any error in logcat.

this is logcat:

02-05 18:38:38.515: D/OpenGLRenderer(27058): Flushing caches (mode 0)
02-05 18:38:42.179: D/TextLayoutCache(27455): Using debug level: 0 - Debug Enabled: 0
02-05 18:38:42.239: D/libEGL(27455): loaded /system/lib/egl/libGLES_android.so
02-05 18:38:42.239: D/libEGL(27455): loaded /system/lib/egl/libEGL_mali.so
02-05 18:38:42.249: D/libEGL(27455): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-05 18:38:42.249: D/libEGL(27455): loaded /system/lib/egl/libGLESv2_mali.so
02-05 18:38:42.279: D/OpenGLRenderer(27455): Enabling debug mode 0
02-05 18:38:50.146: D/OpenGLRenderer(27455): Flushing caches (mode 0)
02-05 18:38:52.148: I/System.out(27455): Random Value0
02-05 18:38:52.348: I/System.out(27455): Random Value4
02-05 18:38:52.579: I/System.out(27455): Random Value2
02-05 18:38:52.789: I/System.out(27455): Random Value1
02-05 18:38:53.029: I/System.out(27455): Random Value2
02-05 18:38:53.219: I/System.out(27455): Random Value4
02-05 18:38:53.420: I/System.out(27455): Random Value1
02-05 18:38:53.620: I/System.out(27455): Random Value1
02-05 18:38:53.830: I/System.out(27455): Random Value5
02-05 18:38:53.870: D/dalvikvm(27455): GC_CONCURRENT freed 1035K, 11% free 9856K/10979K, paused 12ms+2ms
02-05 18:38:54.070: I/System.out(27455): Random Value1
02-05 18:38:54.300: I/System.out(27455): Random Value5
02-05 18:38:54.501: I/System.out(27455): Random Value1
02-05 18:38:54.701: I/System.out(27455): Random Value4
02-05 18:38:54.931: I/System.out(27455): Random Value1
02-05 18:38:55.131: I/System.out(27455): Random Value1 
02-05 18:38:55.331: I/System.out(27455): Random Value1
02-05 18:38:55.532: I/System.out(27455): Random Value1
02-05 18:38:55.732: I/System.out(27455): Random Value1
02-05 18:38:55.942: I/System.out(27455): Random Value3
02-05 18:38:56.162: I/System.out(27455): Random Value1
02-05 18:38:56.362: I/System.out(27455): Random Value4
02-05 18:38:56.563: I/System.out(27455): Random Value5
02-05 18:38:56.763: I/System.out(27455): Random Value0
02-05 18:38:56.973: I/System.out(27455): Random Value2
02-05 18:38:57.193: I/System.out(27455): Random Value4
02-05 18:38:57.393: I/System.out(27455): Random Value3
02-05 18:38:57.594: I/System.out(27455): Random Value4
02-05 18:38:57.794: I/System.out(27455): Random Value4
02-05 18:38:58.004: I/System.out(27455): Random Value0
02-05 18:38:58.204: I/System.out(27455): Random Value0 
02-05 18:38:58.404: I/System.out(27455): Random Value5
02-05 18:38:58.605: I/System.out(27455): Random Value0
02-05 18:38:58.805: I/System.out(27455): Random Value5
02-05 18:38:59.005: I/System.out(27455): Random Value0
02-05 18:38:59.215: I/System.out(27455): Random Value2
02-05 18:38:59.415: I/System.out(27455): Random Value5
02-05 18:38:59.616: I/System.out(27455): Random Value2
02-05 18:38:59.816: I/System.out(27455): Random Value5
02-05 18:39:00.016: I/System.out(27455): Random Value4
02-05 18:39:00.216: I/System.out(27455): Random Value3
02-05 18:39:00.416: I/System.out(27455): Random Value4
02-05 18:39:00.617: I/System.out(27455): Random Value4
02-05 18:39:00.817: I/System.out(27455): Random Value1
02-05 18:39:01.027: I/System.out(27455): Random Value5
02-05 18:39:01.227: I/System.out(27455): Random Value3
02-05 18:39:01.427: I/System.out(27455): Random Value3
02-05 18:39:01.628: I/System.out(27455): Random Value5
02-05 18:39:01.828: I/System.out(27455): Random Value2 
02-05 18:39:02.028: I/System.out(27455): Random Value0
02-05 18:39:02.228: I/System.out(27455): Random Value2
  • 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-06-18T10:46:07+00:00Added an answer on June 18, 2026 at 10:46 am

    I solved the problem. The other answer also was very useful.

    I used following inside the run method.

    handler.postDelayed(this, 200);
    

    and it worked. This is the full answer, see this.

    final Handler handler = new Handler();
    Handler.postDelayed(new Runnable(){
    public void run(){
        int randomNum = random.nextInt(6);
        dice.setImageResource(images[randomNum]);
        handler.postDelayed(this, 200);
        }
     }, 200);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question is very similar to the question posted here .
I know that this is a repeated question. I have found very similar questions
I know that this sort of question has been asked here before, but still
I know that this is a newbie question but I am a newbie so
I know that the audience of JIF is very small in numbers, but that's
I know the common answer for this question, but for some reason I get
I know this question is very common but the main point in my question
I know that this question must have been asked and answered a million times,
I know that this question had already been asked a couple of times before,
I know that this has already been asked here but the answer (using 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.