我是安卓新手。实际上,每当我在 android 屏幕(布局)上双击时,我都想创建一个Toast
。但每当我在屏幕上双击时,什么都没有发生。请解决我的问题。
public class MainActivity extends Activity implements OnDoubleTapListener,OnGestureListener{
int clickCount = 0;
long startTime;
long duration;
static final int MAX_DURATION = 500;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GestureDetector detector = new GestureDetector(this,this);
detector.setOnDoubleTapListener(new OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if(e.getAction()==1)
{
Toast.makeText(getBaseContext(), "onSingleTapConfirmed", Toast.LENGTH_LONG).show();
}
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
if(e.getAction()==1)
{
Toast.makeText(getBaseContext(), "onDoubleTapEvent", Toast.LENGTH_LONG).show();
}
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
if(e.getAction()==1)
{
Toast.makeText(getBaseContext(), "onDoubleTap", Toast.LENGTH_LONG).show();
}
return true;
}
});
}