Rectangle movement with onLongPress on Android

0

I'm trying to make a constant movement of a rectangle on an android screen. By pressing a certain area on the screen I wanted to move that rectangle up. But what happens is that when I press the screen the rectangle moves only the first time by the amount of pixels that I set. It does not continue to move while I'm holding the button on the screen. I've tried using while but the system hangs because it seems like it falls into an infinite loop. Does anyone know how I should do it? Here is the code I used: Na activity:

    @Override
public void onLongPress(MotionEvent motionEvent) {
    int x = (int) motionEvent.getX();
    int y = (int) motionEvent.getY();
        mView.moveRetangulo(x,y);
}

In View:

public void moveRetangulo(int x,int y){
    if ((x>direcionalCima.left)&&(y>direcionalCima.top)&&(x<direcionalCima.right)&&(y<direcionalCima.bottom)){
        retangulo.top -= 10;
        retangulo.bottom -= 10;
    }
}
    
asked by anonymous 19.01.2018 / 21:57

0 answers