GestureDetector Deprecated Issue
Asked Answered
S

3

33

I have this code

itemizedOverlay = new MyItemizedOverlay(drawable,this);
itemizedOverlay.setGestureDetector(new GestureDetector(new MyGestureDetecor()));

but new GestureDetector is marked as Deprecated in Eclipse.

I want to avoid the use of deprecated methods.

How could I fix this problem?

What is the non-deprecated form?

Shrier answered 13/10, 2012 at 13:47 Comment(0)
T
66

Choose one of the other constructors. There are five defined constructors on GestureDetector. Two -- the ones not including a Context as the first parameter -- are marked as deprecated. You are using one of those.

Trumpet answered 13/10, 2012 at 13:52 Comment(3)
@Trumpet what should I pass as context?Rabush
@ThEuSeFuL: I would assume that your Activity is handy and a likely candidate.Trumpet
@Trumpet I just figured it out and now its working I think. Used getBaseContext()Rabush
H
21

There are just two deprecated constructors. If you add the context to GestureDetector(context, listener) it's not deprecated.

Heavyhearted answered 13/10, 2012 at 13:54 Comment(2)
how do i get context in class gesture detectorMedovich
@Sridhar There are several ways. Activity inherits from Context, so you can use this inside an Activity, or maybe you can use getApplicationContext(). See also the comments to @CommonsWare's answer.Heavyhearted
H
-2

1 try add Context to your method: `

itemizedOverlay = new MyItemizedOverlay(drawable,this); itemizedOverlay.setGestureDetector(Context context new GestureDetector(new MyGestureDetecor()));`

2 if you already have call to class Context in your method try:

itemizedOverlay = new MyItemizedOverlay(drawable,this); itemizedOverlay.setGestureDetector(new GestureDetector(context new MyGestureDetecor()));

Hart answered 3/3, 2018 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.