简体   繁体   English

按住按钮但在Android Studio上延迟(LongPress)之后显示窗口

[英]Display a Window while a button is held pressed, but after a delay (LongPress) on Android Studio

I'm doing a calculator app as a college project. 我正在做一个计算器应用程序作为一个大学项目。 I want the "equals" button to (obviously) calculate the result of the operation, but I also want that button to display the history if you keep the button pressed. 我希望“等于”按钮能够(显然)计算操作的结果,但是如果您按住该按钮,我也希望该按钮显示历史记录。

I know how to use OnLongClick but am not sure how to implement this. 我知道如何使用OnLongClick,但不确定如何实现。

Just as with OnClickListener you will have to implement OnLongClickListener and override onLongClick() or use an anonymous inner class for example: 与OnClickListener一样,您将必须实现OnLongClickListener并重写onLongClick()或使用匿名内部类,例如:

equalsButton.setOnLongClickListener(new View.OnLongClickListener() {
   @Override public boolean onLongClick(View v) {
           displayHistory();
       return true;
   }
});

Unlike onClick(), onLongClick returns a boolean. 与onClick()不同,onLongClick返回一个布尔值。 This is to notify the Android OS if the callback has consumed the event or not. 这是为了通知Android OS回调是否已使用该事件。 A return value of true indicates to the OS that the event can be discarded and does not have to be passed on to other event listeners registered on the same button. 返回值true表示向OS表示该事件可以被丢弃,而不必传递给在同一按钮上注册的其他事件侦听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM