title: Drawing more than one rectangle on canvas as user moves finger on screen
body: <p>I used the below code to draw rectangle on canvas as user touches the screen, where the first coordinates are where user first touches screen, it worked.</p>
  
  <p>problem: I am able to draw only one rectangle , when I want to draw a second one the first one disappears (I want to draw as many as I want).</p>
  
  <p>second problem : how to draw triangle and circle using same method?</p>
  
  <p>the code:</p>
  
  <pre><code>//In a custom view class
  int mStartX;
  int mStartY;
  int mEndX;
  int mEndY;
  
  Paint paint = new Paint();
  
  //I did constructor and everything.........
  
  //Drawing the rectangle in on draw
  @Override
  protected void onDraw(Canvas canvas) {
  
  super.onDraw(canvas);
  
  canvas.drawRect(mStartX, mStartY, mEndX, mEndY, paint);
  }
  
  
  //updating the coordinate variables on touch
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
  
  switch (event.getActionMasked()) {
  
      case MotionEvent.ACTION_DOWN:
  
          mStartX = (int) event.getX();
          mStartY = (int) event.getY();
  
          break;
  
      case MotionEvent.ACTION_MOVE:
  
          mEndX = (int) event.getX();
          mEndY = (int) event.getY();
  
          invalidate();
  
          break;
  
      case MotionEvent.ACTION_UP:
  
  
          mEndX = (int) event.getX();
          mEndY = (int) event.getY();
  
          invalidate();
  
          break;
  
      default:
  
          return false;
  
          break;
  }
  
  return true;
  }
  </code></pre>