Android Changing Colors with Thread
<p>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</p>

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

<p>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();</p>

<p>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?</p>

<p>I just need to make a circle change colors in intervals of 2 seconds</p>

<p>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)</p>

<p>Here is the code</p>

<pre><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&lt;20;i++){
                        Thread.sleep(2000);
                        handler.sendMessage(handler.obtainMessage());
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }                     
                };                     
                updateUI.start();       

                }  
</code></pre>

<p>}</p>

<p>That is the Activity and here is my Class</p>

<pre><code>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); 
}
</code></pre>

<p>}</p>
