이 코드가 토스트를 나타내지 않는 이유를 이해할 수 없습니다. OnGestureListener 인터페이스를 구현했으며 사용자가 활동을 스 와이프 할 때 토스트를 표시하려고합니다. onFling 메서드를 호출해야하지만 토스트를받지 못했다는 의미입니다. 문제를 이해하도록 도와주세요.스 와이프 용 OnGestureListener 이해
import android.os.Bundle;
import android.app.Activity;
import android.view.GestureDetector.OnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.Toast;
public class MainActivity extends Activity implements OnGestureListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(this,"onDown",Toast.LENGTH_LONG).show();
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
Toast.makeText(this,"Swipe to Explore the Happiness Path",Toast.LENGTH_LONG).show();
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(this,"onLongPress",Toast.LENGTH_LONG).show();
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// 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`enter code here`
return false;
}
}
감지 만. – GrIsHu
[droidQuery] (http://bit.ly/droidquery) 라이브러리를 사용하여 스 와이프 이벤트를 쉽게 처리 할 수 있습니다. 훌륭한 예를 보려면 [this post] (http://stackoverflow.com/questions/18067336/determining-fling-direction)를 참조하십시오. – Phil