简体   繁体   中英

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.

Just as with OnClickListener you will have to implement OnLongClickListener and override onLongClick() or use an anonymous inner class for example:

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

Unlike onClick(), onLongClick returns a boolean. This is to notify the Android OS if the callback has consumed the event or not. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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