I am implementing a game which is having touch events and I have implemented that but not working. Here is my code for touch listener:
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    if开发者_JAVA百科(action == MotionEvent.ACTION_DOWN)
    {
        if(event.getX()> r.x && event.getX()< (r.x +100) && event.getY()>(r.y-20) && event.getY()<r.y)
        {
            touch = true;
        }
        return true;
    }
    else if(action == MotionEvent.ACTION_MOVE && touch)
    {
        if(event.getX()>0 && event.getX()<220)
        {
            r.x = event.getX();
            r.y = event.getY();
        }
        return true;
    }
    return false;
}
here r is the object of rectangle and x and y are the coordinates of rectangle.
i am writing the touch listener in surfaceview so i have written the listener in activity hence problwm solved
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论