How can I add touch capabilities to a simple bitmap?
I've tried to create a wrapper class for a bitmap,
which implemented OnGestureListener,
but it didn't work.
I want to avoid extending View class to achieve this.
Thanks!
A Bitmap per se is just a representation of an image... thus, in order to show it you will have to draw it somewhere (a View, in fact you always draw it on a View). Then, there's no way to avoid using the View class since all user interface widgets extend it.
In conclusion, if you want to simply set touch listeners to a single Bitmap you can, for instance, draw it on a ImageView and set the appropriate listeners. On the other hand, if you have a set of bitmaps drawn somewhere (for instance, on a SurfaceView), you should locate the bitmap by its coordinates (in that case, the View which would receive the events will be the SurfaceView).
Do you have your OnGestureListener implementation wired to a GestureDetector? The GestureDetector analyzes a MotionEvent and invokes the appropriate callback on the listener based on the type of movement it found.
public class MyActivity extends Activity { private GestureDetector detector; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... detector = new GestureDetector(new MyGestureListener()); ... } @Override public boolean onTouchEvent(MotionEvent event) { return detector.onTouchEvent(event); } }