public class MainActivity extends Activity implements OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@SuppressLint("ShowToast")
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(velocityX < 0){
Toast toast=Toast.makeText(getApplicationContext(), "默認的Toast", Toast.LENGTH_SHORT); }
if(velocityX > 0){
Toast toast=Toast.makeText(getApplicationContext(), "默認的Toast", Toast.LENGTH_SHORT); }
if(velocityY < 0){
Toast toast=Toast.makeText(getApplicationContext(), "默認的Toast", Toast.LENGTH_SHORT); }
if(velocityY > 0){
Toast toast=Toast.makeText(getApplicationContext(), "默認的Toast", Toast.LENGTH_SHORT); }
return false;
}
}
。。因為你只是初始化那個Toast,沒有調用show方法,正確應該是:
Toast.makeText(getApplicationContext(), "默認的Toast", Toast.LENGTH_SHORT).show();