Hi everyone,

I just want to write a basic program that displays the x, y
coordinates when the screen in touched.  Here's my code, any help will
really be appreciated as I'm very much a beginner.

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class touch_tester extends Activity {

    DrawnView dV;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        dV = new DrawnView(this);
        setContentView(dV);
    }
}

class DrawnView extends View implements OnTouchListener {
    Paint paint = new Paint();
    float x, y;

    public DrawnView(Context context){
        super(context);
        this.setClickable(true);
        setBackgroundColor(Color.WHITE);
        this.setOnTouchListener(this);

        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
    }


    public void onDraw(Canvas c){
                c.drawText("X: " + x, 1, 15, paint);
                c.drawText("Y: " + y, 1, 30, paint);
    }

    public boolean onTouch(View view, MotionEvent event){
        x = event.getX();
        y = event.getY();
        return true;
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to