的buttonDown和ButtonUp事件为Android屏幕按钮? [英] ButtonDown and ButtonUp events for Android screen buttons?

查看:565
本文介绍了的buttonDown和ButtonUp事件为Android屏幕按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到一个onButtonDown或onButtonUp事件的软按钮(即不是一个物理硬件按钮,但屏幕上的按钮)?我有,我希望用户按住X秒,屏幕上的按钮。要做到这一点,我需要单独捕获的buttonDown和buttonUp事件。

谢谢

布雷特

解决方案

  yourButton.setOnTouchListener(yourListener);

公共布尔onTouch(查看yourButton,MotionEvent theMotion){
    开关(theMotion.getAction()){
    案例MotionEvent.ACTION_DOWN:打破;
    案例MotionEvent.ACTION_UP:打破;
    }
    返回true;
}
 

Is there a way to get an onButtonDown or onButtonUp event for a soft button (i.e. not a physical hardware button, but a button on the screen)? I have a button on the screen that I want the user to hold down for X seconds. To do this I need to capture the buttonDown and buttonUp events separately.

Thanks,

Bret

解决方案

yourButton.setOnTouchListener( yourListener );

public boolean onTouch( View yourButton , MotionEvent theMotion ) {
    switch ( theMotion.getAction() ) {
    case MotionEvent.ACTION_DOWN: break;
    case MotionEvent.ACTION_UP: break;
    }
    return true;
}

这篇关于的buttonDown和ButtonUp事件为Android屏幕按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆