Keep On Doing An Action While Button Is Pressed After Long Click
Sorry if the title makes no sense. What I'm trying to accomplish is to be able to long click a button, and once the long click is detected, to keep on doing a certain task.
To put it into context, I have a view with a background that changes to a random color on click. I would like to have the background keep on changing color as long as I long click the button. So, basically, upon long click and keeping the button pressed, the background will keep on changing.
Thank you very much folks :)
Answer
This isn't possible with view.setOnLongClickListener()
because an OnLongClickListener has a very specific way of functioning. As soon as enough time has passed, the listener will activate and the code is run.
What you want is to use view.setOnTouchListener()
. This way you can set a Timer when it detects a MotionEvent.ACTION_DOWN
. Once the timer is long enough to equal a long click, you can have it trigger your color changing code repeatedly until the OnTouchListener detects a MotionEvent.ACTION_UP
. That's when you can stop the color changing code.
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View