How can I display a toast message from within a class which extends ImageView. I’d like to place it in the onDoubleTap method so it displays a message to the user as to what pixel was just double tapped. I have the following two classes:
public class TouchImageView extends ImageView
{
....
final GestureDetector mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener()
{
@Override
public boolean onDoubleTap(MotionEvent e)
{
Toast.makeText(getApplicationContext(), "Pixel", Toast.LENGTH_SHORT).show();
return true;
}
...
}
public class DisplayMap extends Activity
{
int width;
int height;
double imageSize;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TouchImageView img = new TouchImageView(getApplicationContext());
Bitmap mapImage = BitmapFactory.decodeResource(getResources(), R.drawable.testimage);
img.setImageBitmap(mapImage);
img.setMaxZoom(4f);
setContentView(img);
...
}
The code above won’t work because
getApplicationContext() is undefined for ImageView.
Thanks
Have your
TouchImageViewclass a constructor that accepts aContextobject.And send your Activity.this object in the TouchImageView object