title: How to draw different points with canvas in Android
body: <p>I'm developing an Android application, I have to implement a function that allow me to draw different point in an activity.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      public Paint paint;
      public List&lt;Point&gt; coords;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(new DrawingView(this));
  
          paint = new Paint();
          coords = new ArrayList();
  
          ImageView iv = new ImageView(getApplicationContext());
          iv.setImageResource(R.drawable.car);
          iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
          LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
          iv.setLayoutParams(parms);
      }
  
      class DrawingView extends SurfaceView {
  
          private final SurfaceHolder surfaceHolder;
          private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  
          public DrawingView(Context context) {
              super(context);
              surfaceHolder = getHolder();
              paint.setColor(Color.BLACK);
              paint.setStyle(Paint.Style.FILL);
          }
  
          @Override
          public boolean onTouchEvent(MotionEvent event) {
              if(event.getAction() == MotionEvent.ACTION_DOWN) {
                addpoint(event.getX(), event.getY());
              }
              return false;
          }
  
          public void addpoint(float x, float y){
  
              Point point = new Point();
              point.x = Math.round(x);
              point.y = Math.round(y);
              coords.add(point);
  
              for(int i = 0; i&lt; coords.size(); i++) {
                  Canvas canvas = surfaceHolder.lockCanvas();
                  canvas.drawColor(Color.WHITE);
                  canvas.drawCircle(coords.get(i).x, coords.get(i).y, 20, paint);
                  surfaceHolder.unlockCanvasAndPost(canvas);
              }
          }
      }
  }
  </code></pre>
  
  <p>Everytime that I touch the screen I get and save the coordinates in a list, then I try to draw the list of point, but only one point remain on the screen, I don't understand why.</p>
  
  <p>So how I can draw different point on the screen (and save it) ?</p>
  
  <p>Another question: how I can show a background image ?</p>