简体   繁体   中英

How to set progress intervals in Range Seekbar

Hai i created a two thumb range seek bar using given example..but now i am facing a problem.. Now I am the getting the min and max value part. The next problem is having custom values for the slider in seekbar. Like i want 500,1000,1500.... etc.but according to example code it values progressing 1,2,3..etc I am providing the code for my main class.

source link: ' https://code.google.com/p/range-seek-bar/

   RangeSeekBar<Integer>seekBar = new RangeSeekBar<Integer>(1000, 1000000, context);

   seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {

   @Override

  public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue,Integer maxValue) 

  {

  //handle changed range values

  Log.i("", "Price Range Values: MIN=" + minValue + ", MAX=" + maxValue);

  String range = "Price Range:" + minValue + "-" + maxValue;

  price_range.setText(range); 

I'm just elaborating rentires idea. So what you need to do is to divide your Min- and Max-Range by 500 and right in your onRangeSeekBarValuesChanged you multiply it by 500.

Code

    int startValue = 1000;
    int endValue = 100000;
    final int factor = 500;
    RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(startValue/factor, endValue/factor, this);
    seekBar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
            minValue = minValue*factor
            maxValue *= factor;
            value.setText(minValue + " : " + maxValue);
        }
    });

In order to make it for the user more transparent which range he has selected you should also enable notifyWhileDragging . (This ensures that the onRangeSeekBarValuesChanged method is called all the time while the user is dragging the RangeSeekBar ).

seekBar.setNotifyWhileDragging(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM