0

I am trying to display the coordinates of a point that a user clicks on the screen using a Toast. its not working in this class for some reasons, can anyone shed some light on why? @Override public boolean onTouchEvent(MotionEvent event) { //motionevent detects motion from the user float x; x = event.getX(); float y; y = event.getY();

      switch (event.getAction())
      {
        case MotionEvent.ACTION_UP:
            //touch_up(x, y);
            invalidate();
            float Cox = event.getX();
            float Coy = event.getY();
            String text = "You clicked at x = " + Cox+ "and y =" + Coy;
            //AlertDialog.Builder builder = new AlertDialog.Builder();
            Toast toast = Toast.makeText(DrawView.this, text, 10);
            toast.show();

            break;
      }
      return true;

1 Answers1

0

Set a class variable called:

Context mContext;

In onCreate method:

mContext = this;

Pass this mContext variable in Toast constructor instead of DrawView.this

MobileMon
  • 8,341
  • 5
  • 56
  • 75