For my app, I was looking for implementation where you keep the button pressed and it continuously keeps updating the value in chunks. Sadly, View.OnLongClickListener doesn't have any such support, so I decided to make a custom listener for this behaviour. You can view the final implementation here -
Some notes on the implementation of this listener -
- To support continuous long click listener, I am attaching 2 listeners to the view object. View.OnLongClickListener and View.OnTouchListener
- View.OnLongClickListener kicks in when it first detects a long click by user. After executing the default behaviour, it adds a delayed message to a Handler to execute the same code. This way, after a stipulated time the same code kicks in and increments the value again and thus simulating the required behaviour for continuous long click.
- View.OnTouchListener is used to detect a MotionEvent.ACTION_UP event, where the user disengages from the screen. On detecting it, any pending messages in the Handler are cleared thus finishing the event.
- As an add-on, I stimulate a haptic feedback every time the code is run to give user feedback about the long click action being kicked in.
The code for the above sample can be found on github here -> https://github.com/anagri/AndroidLearnings
The gist of listener implementation is below ->