I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }

I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }

This code actually will draw it turns out I cant have findViewById(R.id.pageSurface).setBackgroundColor(Color.WHITE); set outside of this method or it will cause the page to remain white...

I still need help to make the line solid. I get a dotted line that is spaced apart based on how fast I move my finger. Is there a way to continue drawing and updating dots while my finger is down?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.