如何在扩展 ImageView 的类中显示 toast 消息。我想把它放在 onDoubleTap 方法中,这样它就会向用户显示一条消息,说明什么像素被双击了。我有以下两个课程:
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);
...
}
上面的代码不起作用,因为 getApplicationContext() 没有为 ImageView 定义。
谢谢