//
you're reading...
HCI, Tech

Three (More) Steps to Use GestureDetector in MapActivity

Based on a simple Google Map application set up (see here), the following three steps allow you to use GestureDetector.

Let the class implement GestureDetector interface

Simply add

/* ... */ implements OnGestureListener{ ...

to your class declaration.

Create a GestureDetector

private GestureDetector gestureDetector;
public void onCreate(Bundle savedInstanceState) {

//...
    gestureDetector = new GestureDetector(this);
//...

Add the GestureDetector to an OnTouchListener

This can be done in one ‘line’ of code. Locate your MapView:

mapView.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event){
// assuming you define your gesturedetector elsewhere
        gestureDetector.onTouchEvent(event);
        return false;
}
 });
Advertisements

About Xiang 'Anthony' Chen

Making an Impact in Your Life

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Twitter Updates

%d bloggers like this: