本文介绍了如何自定义在android系统pssed长/延迟按钮$ P $的时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个应用程序的其中有一个按钮可以执行的操作,但我想,当在谷歌button.Since用户长preSS APPX提供长期preSS持续时间1.5秒执行的操作但我想自定义此持续时间。请帮助...

I am making an app's which have a button to performed an action, but i want to perform the action when user long press on the button.Since Google provides the long press time duration appx .5 sec but I want to customize this time duration. Please help...

推荐答案

您可以尝试触摸监听器来做到这一点。

You can try Touch Listener to do this.

尝试:

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

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

            case MotionEvent.ACTION_CANCEL:
                handler.removeCallbacks(run);
                break;

            case MotionEvent.ACTION_UP:
                handler.removeCallbacks(run);
                break;

            }
            return true;
        }
    });

其中, B 视图要在其上进行长按。

的Runnable 运行如下:

Runnable run = new Runnable() {

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

    }
};

希望它可以帮助...:)

Hope it helps... :)

这篇关于如何自定义在android系统pssed长/延迟按钮$ P $的时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:13