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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:43:48+00:00 2026-05-19T17:43:48+00:00

I am a bit frustrated as to how to do this.., Can anyone please

  • 0

I am a bit frustrated as to how to do this.., Can anyone please help me or guide me in the right direction?, with the code below. I just need to make a circle change colors in 2 second intervals, and i cant find anything out there.. basically if I could understand the following it would be enough

1.I have a class call DrawCircle that Exatends View
2.I have the Activity program where I instantiate the DrawCircle Class.
Questions:

1 – Where Do I create the Thread? in Activity or in the DrawCircle class?, and if I do, what should i put in the run();

2 – Where would I put the “Thread.sleep(2000)”? 3. and Finally, what do i need to make sure I have in the DrawCircle class and what should I make sure I have in the Activity or main program?

I just need to make a circle change colors in intervals of 2 seconds

Thank you very much for all the help ( I have spent 12 hours already trying to make this work and maybe I just shouldnt do it anymore)

Here is the code

public class ColorChanges extends Activity { 
  DrawCircle dc;   
  Paint pa = new Paint();


  @Override 
  public void onCreate(Bundle savedInstanceState) 
    {     
         super.onCreate(savedInstanceState); 

              //this line does not work

            dc = new DrawCircle(this,pa); 
            dc.setBackgroundColor(Color.WHITE);     
            drawCircleToCanvas();
            setContentView(dc);    
          }  

   void drawCircleToCanvas()   
    {      

       final Handler handler = new Handler() 
          {                  
            public void handleMessage(Message msg) {
                pa.setColor(Color.BLUE);
                 dc.setBackgroundColor(Color.RED);

                 dc.postInvalidate();                         
                 }                 
            };          
            Thread updateUI = new Thread()       
            {                        
                public void run() {                              

                    try {
                        for (int i=0;i<20;i++){
                        Thread.sleep(2000);
                        handler.sendMessage(handler.obtainMessage());
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }                     
                };                     
                updateUI.start();       

                }  

}

That is the Activity and here is my Class

public class DrawCircle extends View {
Paint p1 = new Paint();
Paint p2 = new Paint();
Paint p3 = new Paint();

Paint pAll[] = new Paint[3];


public DrawCircle(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}
public DrawCircle(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
}

public DrawCircle(Context context, Paint p) {
    super(context);
       p1 = p;
       p1.setStyle(Paint.Style.STROKE);
       p1.setColor(Color.GREEN);
       p1.setStyle(Paint.Style.FILL);



    // TODO Auto-generated constructor stub
}

@Override  
public void onDraw(Canvas canvas) 
{     

             canvas.drawCircle(200, 200, 100, p1); 
}

}

  • 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-19T17:43:49+00:00Added an answer on May 19, 2026 at 5:43 pm

    Do it in the UI thread. Instead of Thread.sleep, use Handler.postDelayed() with a two-second delay.

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

Sidebar

Related Questions

This is a bit of a long shot, but if anyone can figure it
Bit of an obscure one this. My setup is all running on my local
A bit of a neophyte haskell question, but I came across this example in
A bit of background first: I am using base code from a remote SVN
I just wonder a bit whether or not GDI+ is still a technology worth
The following bit of code catches the EOS Exception using (var reader = new
This is a bit of a silly question but I don't know how to
Bit tricky to communicate but hope this makes sense. I have 8 div containers
Bit rusty in sql I have a situation where I need to insert a
any bit of info will be helpful here. or does anybody else huge do

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.