Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked August 1st 2010 by J T
  • click
  • mobile
  • slider
0 Comments

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 
    }
    
    }
    )
    
    — answered August 2nd 2010 by Dan Tamas
    permalink
    0 Comments
  • 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.

    — answered August 2nd 2010 by Goran Skledar
    permalink
    1 Comment
    • Thanks, but that does not work..

      If i created lets say my slider like this:

      var sl = Ti.UI.createSlider({
      height:'auto',
      width:200,
      touchEnabled: true
      });
      
      sl.addEventListener('click', function() {
      alert('Clicked the slider');
      });
      

      The click event simply does not get fired.. :(

      — commented August 2nd 2010 by J T
  • 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.

    — answered August 2nd 2010 by Dan Tamas
    permalink
    1 Comment
    • Thanks! But how you mean set a flag? I'm not quitte sure if i understand what you mean..

      Thanks!

      — commented August 2nd 2010 by J T
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.