我已經查看了許多在線示例,並且它們都以這種方式實現了gesturelistener。我無法讓android拿起手勢事件myText的值不會改變,我沒有在logcat中得到任何輸出。我究竟做錯了什麼?Android GestureListener未檢測到事件
public class MainActivity extends Activity {
private GestureDetector gDetector;
private TextView myText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gDetector = new GestureDetector(this, new MyOnGestureListener());
myText = (TextView) findViewById(R.id.mytext);
myText.setText("Test");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class MyOnGestureListener extends SimpleOnGestureListener implements
OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
Log.d("Main", "did");
myText.setText("hi");
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
myText.setText("hi");
Log.d("Main", "did");
// TODO Auto-generated method stub
return true;
}
@Override
public void onLongPress(MotionEvent e) {
Log.d("Main", "did");
myText.setText("hi");
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.d("Main", "did");
myText.setText("hi");
// TODO Auto-generated method stub
return true;
}
@Override
public void onShowPress(MotionEvent e) {
Log.d("Main", "did");
myText.setText("hi");
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.d("Main", "did");
myText.setText("hi");
// TODO Auto-generated method stub
return true;
}
}
}
嘿,我想申請一個姿態探測器的MapView的。我使用你描述的方法,在這裏我定義了我的GestureDetector類,並以你在這裏描述的方式調用mMapView.setOnTouchListner()。我沒有得到任何onTouchEvent()命中。你能告訴我爲什麼嗎? – KairisCharm