Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

touch listener and long click listener

i wrote a code with touch listener on surface view to move object and it work great, when i insert on long click listener the touch listener stop working well and the object move even if i not touch it. the long clickneed to open dialog.

on create:

sf = new SurfaceView(this);
sf.setOnTouchListener(this);
sf.setOnLongClickListener(this);

on Long Click:

public boolean onLongClick(View v) {
    if (!changePositionMode){
        final Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.text_manager);
        dialog.setTitle("Browser");
        dialog.setCancelable(true);
        dialog.show();
    }
    return false;
}

on touch listener

public boolean onTouch(View v, MotionEvent event) {
    Point p=new Point((int)event.getX(),(int)event.getY());
    if (event.getAction()==MotionEvent.ACTION_DOWN){
        }else if (object.isTouch(p)){
            changePositionMode=true;
            x=event.getX();
            y=event.getY();
            draw();
            return true;
        }   
    }
    else if (event.getAction()==MotionEvent.ACTION_MOVE){
        t.changeTamplatePosition(event.getX()-x,event.getY()-y);
        x=event.getX();
        y=event.getY();
        draw();
        return true;
    }
    else if (event.getAction()==MotionEvent.ACTION_UP){
        changePositionMode=false;
    }

    return false;
}
like image 846
tzahibs Avatar asked Jan 27 '26 14:01

tzahibs


1 Answers

You have to return false instead of true in OnTouch(View v,MotionEvent event) function so that other listeners(OnLongClickListener) on the control remains active.

like image 68
Nikhil Raut Avatar answered Jan 29 '26 02:01

Nikhil Raut