Reputation: 6836
The objective here is to place markers on google maps.
I want to place the marker when the user does a longClick().
Problem. The long click listener does not have the data about where the user clicked. I can only know that he actually clicked. Also, if I use the touch event and I don't consume it (I require that for the map to use its default listener for the scrolling) I don't be listening to any other touch events, even if the touch resets. (that does not happen for the other events, afaik).
How to I know where the user did the longClick so that I can place a marker there in the map?
Upvotes: 0
Views: 1101
Reputation: 2581
Check if this helps to detect long click. The onFinish()
method of the CountdownTimer
is the where you need to place your code to add markers.
It will work for detecting long click, not sure whether it will override scrolling behavior of MapView
;)
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d("action down", "action down started");
countDownTimer = new CountDownTimer(2500, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"long clicked", Toast.LENGTH_SHORT).show();
}
};
countDownTimer.start();
Log.d("action down", "action down ended");
break;
case MotionEvent.ACTION_UP:
countDownTimer.cancel();
countDownTimer = null;
break;
default:
break;
}
return false;
}
Upvotes: 0
Reputation: 2541
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
dosomething
return true; // processed the event
default:
return false;
}
}
this will allow you to process the ACTION_DOWN event, and have default processing for all others.
Upvotes: 1