I have a range seek bar in my app. I need to call a method by passing the min value of the bar only if the value is changed and also to call another method by passing the max value if the max value is changed. Here is my code so far.
rangeSeekbar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
//call this if min value is changed
mywebView.loadUrl("javascript:setStart(" + minValue.intValue() + ")");
//call this if max value is changed
mywebView.loadUrl("javascript:setEnd(" + maxValue.intValue() + ")");
}
Toast.makeText(getApplicationContext(), minValue + "-" + maxValue, Toast.LENGTH_LONG).show();
}
});
The problem is when only one value changes, both methods are called. How can I differentiate the method calls? Any ideas are welcome.
You can declare a field variable to save the value you have changed:
int min ,max;
rangeSeekbar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
if(minValue.intValue!=min){
//call this if min value is changed
mywebView.loadUrl("javascript:setStart(" + minValue.intValue() + ")");
min = minValue.intValue;
}
if(maxValue.intValue!=max){
//call this if max value is changed
mywebView.loadUrl("javascript:setStart(" + maxValue.intValue() + ")");
max = maxValue.intValue;
}
}
});
min
and max
if you can confirm.