- 论坛徽章:
- 0
|
- public class test2 extends Activity implements OnTouchListener, OnClickListener{
-
/** Called when the activity is first created. */
-
-
GestureDetector mGestureDetector;
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
-
Button btn = (Button)this.findViewById(R.id.button1);
-
btn.setOnTouchListener(this);
-
btn.setOnClickListener(this);
-
- //创建一个手势dectector
-
mGestureDetector = new GestureDetector(this, new CalendarGestureListener());
-
}
-
-
@Override
-
public boolean onTouch(View v, MotionEvent event) {
-
if (mGestureDetector.onTouchEvent(event)) {
-
return true;
-
}
-
return super.onTouchEvent(event);
-
}
-
-
-
class CalendarGestureListener extends GestureDetector.SimpleOnGestureListener {
-
-
/* (non-Javadoc)
-
* @see android.view.GestureDetector.SimpleOnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
-
*/
-
@Override
-
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
-
float velocityY) {
-
Log.v("touch", "x=" + Float.toString(e1.getX()) + " x2=" + Float.toString(e2.getX()) );
-
// TODO Auto-generated method stub
-
return super.onFling(e1, e2, velocityX, velocityY);
-
}
-
}
-
-
-
@Override
-
public void onClick(View arg0) {
-
// TODO Auto-generated method stub
-
Log.v("touch", "Hello, Click Me" );
-
-
}
-
}
|
|