按钮按下与松开

来源:互联网 发布:淘宝客服沟通技巧简答 编辑:程序博客网 时间:2024/05/17 05:14

android.view.View.OnTouchListener


Interface definition for a callback to be invoked when a touch event is dispatched to this view. The callback will be invoked before the touch event is given to the view.





android.view.MotionEvent

Object used to report movement (mouse, pen, finger, trackball) events. Motion events may hold either absolute or relative movements and other data, depending on the type of device.

View.OnTouchListener buttonListener = new View.OnTouchListener() {    public boolean onTouch(View v, MotionEvent event) {        switch(v.getId()){            case R.id.aleft:                int action = event.getAction();                if (action == MotionEvent.ACTION_DOWN) { // 按下                    sendInfo="aleft";                    sendInfo();                } else if (action == MotionEvent.ACTION_UP) { // 松开                    sendInfo="bleft";                    sendInfo();                }                break;            case R.id.aright:                action = event.getAction();                if (action == MotionEvent.ACTION_DOWN) { // 按下                    sendInfo="aright";                    sendInfo();                } else if (action == MotionEvent.ACTION_UP) { // 松开                    sendInfo="bright";                    sendInfo();                }                break;        }        return false;    }};aleft.setOnTouchListener(buttonListener);forward.setOnTouchListener(buttonListener);

阅读全文
0 0
原创粉丝点击