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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With