i have written a class to do this.
use:
new SetOnLongTouch(tv_main, new SetOnLongTouch.onLongTouchListener() {
@Override
public void onLongTouch(View v, float X,float Y) {
Log.d("TEST","X:" + X + " Y:" + Y);
}
});
Class:
import android.view.MotionEvent;
import android.view.View;
class SetOnLongTouch {
View view;
private float[] lastTouchDownXY = new float[2];
onLongTouchListener listener;
SetOnLongTouch(View v,onLongTouchListener onLongTouchListener){
view = v;
listener = onLongTouchListener;
v.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
lastTouchDownXY[0] = motionEvent.getX();
lastTouchDownXY[1] = motionEvent.getY();
}else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
view.performClick();
}
return false;
}
});
v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
listener.onLongTouch(view,lastTouchDownXY[0],lastTouchDownXY[1]);
return true;
}
});
}
public interface onLongTouchListener{
void onLongTouch(View v, float X, float Y);
}
}
if you are a newbie like me then it also gives you the idea that how these listener works and how,why and where use interfaces.