Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304552
  • 博文数量: 53
  • 博客积分: 1266
  • 博客等级: 少尉
  • 技术积分: 572
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-16 16:45
文章分类

全部博文(53)

文章存档

2012年(37)

2011年(16)

分类: 嵌入式

2011-10-18 15:34:17

一、            按下按键触发事件:

    // 按键按下触发事件

    public boolean onKeyDown(int keyCode, KeyEvent event) {

       switch (keyCode) {

       case KeyEvent.KEYCODE_DPAD_CENTER:

           DisplayToast("按下:中键");

           break;

       case KeyEvent.KEYCODE_DPAD_UP:

           DisplayToast("按下:向上键");

           break;

       case KeyEvent.KEYCODE_DPAD_DOWN:

           DisplayToast("按下:下方键");

           break;

       case KeyEvent.KEYCODE_DPAD_LEFT:

           DisplayToast("按下:左方键");

           break;

       case KeyEvent.KEYCODE_DPAD_RIGHT:

           DisplayToast("按下:右方键");

           break;

       }

 

       return super.onKeyDown(keyCode, event);

    }

 

二、            弹起按键触发事件:

// 按键弹起触发事件

    public boolean onKeyUp(int keyCode, KeyEvent event) {

       switch (keyCode) {

       case KeyEvent.KEYCODE_DPAD_CENTER:

           DisplayToast("弹起:中键");

           break;

       case KeyEvent.KEYCODE_DPAD_UP:

           DisplayToast("弹起:向上键");

           break;

       case KeyEvent.KEYCODE_DPAD_DOWN:

           DisplayToast("弹起:下方键");

           break;

       case KeyEvent.KEYCODE_DPAD_LEFT:

           DisplayToast("弹起:左方键");

           break;

       case KeyEvent.KEYCODE_DPAD_RIGHT:

           DisplayToast("弹起:右方键");

           break;

       }

 

       return super.onKeyUp(keyCode, event);

    }

 

三、            笔触事件响应

   // 笔触事件

    public boolean onTouchEvent(MotionEvent event) {

       int iAction = event.getAction();

       if (iAction == MotionEvent.ACTION_CANCEL

              || iAction == MotionEvent.ACTION_DOWN

              || iAction == MotionEvent.ACTION_MOVE) {

           return false;

       }

       int x = (int) event.getX();

       int y = (int) event.getY();

 

       DisplayToast("触笔点击坐标:(" + Integer.toString(x) + ","

              + Integer.toString(y) + "");

 

       return super.onTouchEvent(event);

    }

 

四、            onKeyMultiple

指多个连续的重复事件,可拆开为多个上面的ACTION_DOWNACTION_UP理解,直接接收到ACTION_MULTIPLE这个KeyEvent的时候,onKeyMultiple才会触发

public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {

       return super.onKeyMultiple(keyCode, repeatCount, event);

}

 

五、            构造返回键

public boolean onKeyDown(int keyCode,KeyEvent event){

    KeyEvent key = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_BACK);

    return super.onKeyDown(key.getkeyCode(),key);

}

阅读(5536) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

520xiaobai2014-05-12 14:24:48

学习了