clicklistener 和 longclicklistener 在同一个按钮上? [英] clicklistener and longclicklistener on the same button?
问题描述
我正在创建一个呼叫/拨号按钮,当我单击该呼叫/拨号按钮时,将根据编辑文本中显示的输入进行呼叫.我设法做到了那部分.你们能告诉我我是否可以在同一个呼叫/拨号按钮上单击更长的时间,以便吐司可以出来要求用户选择其他东西?
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"是否可以在代码中的某个地方组合在一起?
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);
}
此代码正在运行.我希望可以在同一个呼叫/拨号按钮上进行更长的单击,以便该按钮可以正常单击以拨打电话,并且单击更长的时间以弹出敬酒.提前致谢.
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.
推荐答案
请注意,在长单击侦听器上返回false"将使 UI 也将长单击响应为短单击.如果你想杀死它,请返回true".真"表示是的,我使用了这个事件",假"表示无论我是否使用,环境也可以自由响应".(我知道这一点是因为我刚刚在自己的应用中使用了 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屋!