Chinaunix首页 | 论坛 | 博客
  • 博客访问: 138236
  • 博文数量: 38
  • 博客积分: 1605
  • 博客等级: 上尉
  • 技术积分: 370
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-12 14:59
文章分类

全部博文(38)

文章存档

2013年(3)

2012年(8)

2011年(28)

分类: 嵌入式

2011-09-09 13:34:11

  1. public class test2 extends Activity implements OnTouchListener, OnClickListener{
  2.     /** Called when the activity is first created. */
  3.     
  4.     GestureDetector mGestureDetector;
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.main);
  9.         
  10.         Button btn = (Button)this.findViewById(R.id.button1);
  11.         btn.setOnTouchListener(this);
  12.         btn.setOnClickListener(this);
  13.        
  14.         //创建一个手势dectector
  15.         mGestureDetector = new GestureDetector(this, new CalendarGestureListener());
  16.     }

  17.     @Override
  18.     public boolean onTouch(View v, MotionEvent event) {
  19.         if (mGestureDetector.onTouchEvent(event)) {
  20.             return true;
  21.         }
  22.         return super.onTouchEvent(event);
  23.     }
  24.     
  25.     
  26.      class CalendarGestureListener extends GestureDetector.SimpleOnGestureListener {

  27.         /* (non-Javadoc)
  28.          * @see android.view.GestureDetector.SimpleOnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
  29.          */
  30.         @Override
  31.         public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  32.                 float velocityY) {
  33.             Log.v("touch", "x=" + Float.toString(e1.getX()) + " x2=" + Float.toString(e2.getX()) );
  34.             // TODO Auto-generated method stub
  35.             return super.onFling(e1, e2, velocityX, velocityY);
  36.         }
  37.      }


  38.     @Override
  39.     public void onClick(View arg0) {
  40.         // TODO Auto-generated method stub
  41.         Log.v("touch", "Hello, Click Me" );

  42.     }
  43. }
阅读(1100) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~