我在网上查看了许多示例,它们都以这种方式实现了手势监听器。我无法让 android 接收手势事件,myText 的值没有改变,并且我在 logcat 中没有得到任何输出。我究竟做错了什么?
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;
}
}
}