Run Time I have change the background image(set background). In the image, I have perform the action using Touch Listener. But in my case, I need another action on Touch event. For that purpose I need to proceed with long touch event. Suggest me, any other idea.
Asked
Active
Viewed 715 times
2
-
http://stackoverflow.com/questions/4324362/detect-touch-press-vs-long-press-vs-movement – Amrut Bidri May 05 '15 at 12:30
-
@ScionofIkshvaku How to get Motion event value in imageButton.setOnLongClickListener ? – Mercy Angel May 05 '15 at 12:47
-
you can get the values using `ev.getX()` or `ev.getX()` on `MotionEvent.ACTION_MOVE` – Amrut Bidri May 05 '15 at 13:30
-
Cant able to get MotionEvent in imageButton.setOnLongClickListener. – Mercy Angel May 05 '15 at 13:38
-
not in long click use `onTouchEvent` method in `TouchLIstener` – Amrut Bidri May 05 '15 at 14:19
-
I need solution for long click, could you please guide me if any possible way. – Mercy Angel May 05 '15 at 14:23
-
u need x, y values when long click is performed? right? – Amrut Bidri May 05 '15 at 14:36
-
Yes .i need x and y values on long click. – Mercy Angel May 05 '15 at 14:38
-
then update your question accordingly – Amrut Bidri May 05 '15 at 14:41
-
Still Am searching the solution. – Mercy Angel May 06 '15 at 06:36
2 Answers
2
Answering from here:
final Handler handler = new Handler();
Runnable mLongPressed = new Runnable() {
public void run() {
Log.i("", "Long press!");
if(myEvent!=null)
{
int requiredXvalue=myEvent.getX();
int requiredYvalue=myEvent.getY();
}
}
};
MotionEvent myEvent;
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView){
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
handler.postDelayed(mLongPressed, 1000);
myEvent=event;
}
if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP))
handler.removeCallbacks(mLongPressed);
return super.onTouchEvent(event, mapView);
}
OR
you can use Gesture Detector as answered here:
final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
Log.e("", "Longpress detected");
int requiredXvalue=e.getX();
int requiredYvalue=e.getY();
}
});
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
};

Community
- 1
- 1

Amrut Bidri
- 6,276
- 6
- 38
- 80
-
-
Am using imageView on relative Layout. Which detail I have to provide instead of MapView. – Mercy Angel May 07 '15 at 05:06
-
-
'Override public boolean onTouchEvent(MotionEvent event, ImageView btn) { if(event.getAction() == MotionEvent.ACTION_DOWN) { handler.postDelayed(mLongPressed, 1000); myevent=event; } if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP)) handler.removeCallbacks(mLongPressed); return onTouchEvent(event,btn); }' Shows the error in @Override – Mercy Angel May 07 '15 at 06:24
-
-
http://stackoverflow.com/questions/29014212/how-to-place-pin-mark-image-over-an-image-in-android am searching result for that. here am loading 1st image in relative layout(setting as background image) – Mercy Angel May 07 '15 at 07:49
-
Next step Overlay another imageView(Mark) during the onTouch. In my case, I need onTouch to perform Zoom and longTouch to place the imageView. After placing the imageView, Performing the action. – Mercy Angel May 07 '15 at 07:55
-
-
can I able to set onLongPress for particular layout(Relative Layout) in a Activity – reegan29 May 12 '15 at 13:40
0
imageButton.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}
});

Don Chakkappan
- 7,397
- 5
- 44
- 59
-
I believe in this case `onLongClick` should actually return `true`, as the touch event should be consumed – Ed Holloway-George May 05 '15 at 11:28
-