Zankhna
Zankhna

Reputation: 4563

Custom Seekbar with min and max values - Android

I want Seekbar with different start position other than 0 similar to this link. I want to perform same functionality as shown in linked question and i want to allow user to change value between 0-200.Initially Seekbar pointer should be at position of 100 and user should be allowed to move it in left or right direction and accoring to that seek values should be changed. After searching i came to conclusion that i will have to create Custom Seekbar,but i haven't found any good tutorial which will solve my problem. If anybody have any good tutorials then please post link. Thank you.

Upvotes: 0

Views: 6424

Answers (1)

cooperok
cooperok

Reputation: 4267

Try to use this. It's very simple in use

// create RangeSeekBar as Integer range between 20 and 75
RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(20, 75, context);
seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
    @Override
    public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
            // handle changed range values
            Log.i(TAG, "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue);
    }
});

// add RangeSeekBar to pre-defined layout
ViewGroup layout = (ViewGroup) findViewById(<your-layout-id>);
layout.addView(seekBar);

To set values you want, you can call setSelectedMaxValue, setSelectedMinValue methods.

Upvotes: 1

Related Questions