clicklistener和longclicklistener在同一个按钮? [英] clicklistener and longclicklistener on the same button?

查看:163
本文介绍了clicklistener和longclicklistener在同一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个电话/拨号键,当我点击该呼叫/拨号键,通话将根据所显示的EditText上输入进行。我成功地做到这一点的一部分。你们可以告诉我,我是否可以做一个较长的点击相同的呼叫/拨号键,以便举杯可以出来询问用户选择别的东西?

i am creating a call/dial button, when i click on that call/dial button, a call will be made based on the input that is displayed in the edittext. I managed to do that part. can you guys advise me whether i can do a longer click on that same call/dial button, so that a toast can come out to ask user to choose something else??

我做的setOnLongClickListener一些研究,但我不知道我是否可以在同一个电话结合起来/拨号键?我已经贴在我设法做工作拨号功能,想知道如果setOnLongClickListener可以somehere在code结合在一起?

I did some research on "setOnLongClickListener" but i am not sure if i can combine it in the same call/dial button? I have attached on the working dial function which i managed to do, wondering if the "setOnLongClickListener" can be combined together somehere in the code?

    private void dialANumber() {

    try {
        buttonCall = (ImageButton) findViewById(R.id.imageButton2);
        buttonCall.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                if (display != null) {
                    Intent callNumber = new Intent();
                    callNumber
                            .setAction(android.content.Intent.ACTION_CALL);
                    callNumber.setData(Uri.parse("tel:" + display.getText()));
                    startActivity(callNumber);
                }
            }
        });

    } catch (ActivityNotFoundException anfe) {
        Log.e("DialANumber", "Dialing the number failed", anfe);

    }

这code的工作。我希望更长的点击可以在同一呼叫进行/拨号键使按键可以有一个正常的点击拨打电话,并再点击弹出出来敬酒。先谢谢了。

this code is working. i hope a longer click can be made on the same call/dial button so the button can have a normal click to make a call, and longer click to pop out a toast. Thanks in advance.

推荐答案

注意,返回假的长按听众将有UI响应长按为短按一下了。如果你想要杀了那个关返回真。 真的意思是是的,我用这个事件和假的意思是我是否使用与否,环境自由地作出反应。 (我知道这是因为我只是用AkashG的回答在我自己的应用程序。)

Note that returning "false" on the long click listener will have the UI responding to the long click as a short click too. Return "true" if you want to kill that off. "True" means "yes, I used this event" and "false" means "whether I used it or not, the environment is free to respond as well." (I know this because I just used AkashG's answer in my own app.)

这篇关于clicklistener和longclicklistener在同一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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