title: onDraw() for View
body: <p>I just created one view in my layout file here:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"&gt;
      &lt;com.shawntesting.MyView android:layout_above="@+id/button1" android:layout_alignParentTop="true" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/myview1"&gt;&lt;/com.shawntesting.MyView&gt;
      &lt;Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_alignParentBottom="true" &gt;&lt;/Button&gt;
      &lt;Button android:id="@+id/button2" android:text="button2" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And this is my view code:</p>
  
  <pre><code>    public class MyView extends View{
  
  
  
     Paint paint;
  
  
     public MyView(Context context, AttributeSet attrs){ 
         super(context,attrs);
         paint=new Paint();
         paint.setColor(Color.WHITE);
  
     }
  
  
     public void setblue(){
  
        paint.setColor(Color.BLUE);
        this.postInvalidate();
  
     }
     public void setgreen(){
  
         paint.setColor(Color.GREEN);
         this.postInvalidate();
     }
  
    public void onDraw(Canvas canvas){     
            super.onDraw(canvas);
              canvas.drawRect(x, y, 100, 50, paint);
              String i=new String();
              Log.i("getColor",i.valueOf(paint.getColor()));
  
  
         }
  
  }
  </code></pre>
  
  <p>And last is my main activity:</p>
  
  <pre><code>    public class Activity2 extends Activity{
      MyView mv;
      AttributeSet attributes;
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          XmlPullParser parser = getResources().getXml(R.layout.main);
           attributes = Xml.asAttributeSet(parser);
           mv=new MyView(this,attributes);
  
          setContentView(R.layout.main);
          Button b1=(Button)findViewById(R.id.button1);
          Button b2=(Button)findViewById(R.id.button2);
          b1.setOnClickListener(new Button.OnClickListener(){
  
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  mv.setblue();
                  //mv=(MyView)findViewById(R.id.myview1);
                  //mv.invalidate();
  
              }
  
          });
          b2.setOnClickListener(new Button.OnClickListener(){
  
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  mv.setgreen();
                  //mv=(MyView)findViewById(R.id.myview1);
                  //mv.invalidate();
  
              }
  
          });
      }
  }
  </code></pre>
  
  <p>My question is after clicking the button, the view is not refreshed.
  And i also found that after clicking the button, the onDraw() is performing 2times(first for press down the button,second for loose the clicking) why that happened?</p>