Search code examples
androidontouchlistenerontouch

onTouch is not working


I used processing for draw something. After that exporting for android. So I should use this class. public class DrawMap extends PApplet implements View.OnTouchListener My problem is I need to detect when someone is touch on the screen but this is not working properly.

@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    boolean touching;

    if(event.getAction() == MotionEvent.ACTION_UP){
        touching = false;
    }else if(event.getAction() == MotionEvent.ACTION_DOWN){
        touching = true;
    }

    float touch_x = event.getX();
    float touch_y = event.getY();

    return true;

}

Solution

  • If you forget associate each other may not working. This is how you implement a touch listener in Android.

        view.setOnTouchListener(this);