Titanium Community Questions & Answer Archive

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

Fixed values for a Titanium.UI.Slider object

I want my slider to have a value in a range between 0 and 100, but instead of allowing all numbers in the range I want to restrict the user to select certain values only, for example: 10, 15, 20, 25 and so on.

Any thoughts?

— asked March 24th 2010 by Diego Pardo
  • fixed
  • slider
  • values

2 Answers

  • I think you will need to preventDefault() on the various touch events and write your own code in those events to track the user's finger on the slider, manually setting the slider to the nearest valid value as the finger moves along.

    It may be possible to avoid the tracking by just setting the slider to the nearest value directly on the touch events, but I suspect this might create some visual 'snap to value' anomalies - may or may not be what you're after. Worth trying though.

    — answered March 24th 2010 by James K
  • Thsi is what I've done with my slider which only shows the whole number.

    // Create sliding event handler
    sliderAge.addEventListener('change', function(e){
        var nAge = Math.round(e.value);
        sliderLabelAge.text = nAge;
    — answered March 24th 2010 by William Xue
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.