Sliders, click events?
I'm using a slider which gets updated using a setInterval. But i also want the slider to detect when a user clicks it & drags it to a certain point so i can get that value.. (Like a timeline in a audio player).
But how is that done? Since the api tells me:
click
fired when the device detects a click (longer than touch) against the view.
It says VIEW, but it's written at the UI.Slider desc.. does this mean it just can't handle clicks? Or detect any other events, except for the change event?
Thanks!
3 Answers
-
Accepted Answer
You said you have a setInterval that update the slider.
So you could do something like this:var slider_changed_by_me = false; // this is global - this is the flag function_in_setInterval() { slider_changed_by_me = true; ... your stuff ( slider.value=.... ) } the_slider.addEventListener('change', function() { if ( slider_changed_by_me ) { slider_changed_by_me = false; // we reset this once the event was triggered //don't do nothing } else { // user triggered the change because slider_changed_by_me is false ... your stuff } } )
-
You should be able to detect a click by handling the click event.
UI controls inherit most events from Views - that's why it says View in the event's description.
-
Slider seems to be a little buggy right now. So you will have to use the change event.
https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets?q=slider&filter=If "change" event triggers when you do it by code too, you can set a flag to detect if the change was done by your code or by user.