which causes the custom button text update UI Thread (or) onDraw in Android
<p>I subclassed a class to Button and overriden the onDraw() method. And have written a handler in the constuctor of the class where I am updating a variable whose value has to be updated to that button text. Below is the code snippet,</p>

<pre><code>   public class CustomButton extends Button{



        CustomButton(){
                handler = new Handler();
                Runnable runObj = new Runnable(){
                  public void run(){
                      counter++;
                      handler.postDelayed(this,1000);                  
                  }
                };
               handler.post(runObj);
        }

    @Override
    protected void onDraw(Canvas canvas){
        super.onDraw(canvas);       
        setBackgroundResource(R.drawable.button9patch);     
        setTextColor(COMPONENTTEXTCOLOR);
        setText(counter);       
    }

   }
</code></pre>

<p>Well the button text gets updated. I know that the onDraw() method gets called when the button gets rendered initially and when we do some amendments to the button view like setting the label or image etc.,.</p>

<p>Here in my code I am updating the counter outside of the onDraw() method, but calling the setText(counter) explicitly from onDraw() method. As I am not calling setText(counter) from the Hanlder code <strong>How it is updating the button text periodically?</strong> </p>

<p>Is it that the UI thread that causes the counter variable changes updated to the button periodically?</p>

<p>I am confused.</p>

<p>Thanks</p>
