我怎样才能按钮pressed的时候,我抱着按钮 [英] How can I get button pressed time when I holding button on

查看:117
本文介绍了我怎样才能按钮pressed的时候,我抱着按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,我preSS,并继续持有它,如果持有时间超过一定的时间间隔就触发某种意图,我怎么能做到这一点。 谢谢

I have a button, I press it and continue to holding it, if holding time exceeds certain time interval it fires some kind of intent, how can i do this. Thanks

推荐答案

试试这个

您可以使用触摸监听器做到这一点。

You can use Touch Listener to do this.

尝试:

Handler handel = new Handler();
    b.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            switch (arg1.getAction()) {
            case MotionEvent.ACTION_DOWN:
                handel.postDelayed(run, 5000/* OR the amount of time you want */);
                break;

            default:
                handel.removeCallbacks(run);
                break;

            }
            return true;
        }
    });

其中, B 视图(在你的情况下,它应该按钮)要进行长时间点击

Where b is the view (in your case it should button) on which you want to make long click.

的Runnable 运行如下:

Runnable run = new Runnable() {

    @Override
    public void run() {
        // Your code to run on long click

    }
};

希望这将有助于...:)

Hope it will help... :)

这篇关于我怎样才能按钮pressed的时候,我抱着按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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