oli107 / material-range-bar

Android widget for selecting a range of values.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It has problem in showing some ranges

mahdit83 opened this issue · comments

Hi, good work for this cool library but I found a problem in showing data on pins.
for Example if you set setTickStart=10,000 and setTickEnd=500,000 with setTickInterval=10,000 , range changes from 1000 to 5000 and think this part need some revisions.
with regards

Hi, I just had same issue for one of my project. So as I checked the library and found text is trimming from below code.

private PinTextFormatter mPinTextFormatter = new PinTextFormatter() {
	@Override
	public String getText(String value) {
		if (value.length() > 4) {
			return value.substring(0, 4);
		} else {
			return value;
		}
	}
};

So you can tackle this issue from below method.

mRangeBarPrice.setPinTextListener(new RangeBar.OnRangeBarTextListener() {
	@Override
	public String getPinValue(RangeBar rangeBar, int tickIndex) {
		int pinValue = Math.round((float) mRangeBarPrice.getTickInterval() * tickIndex);

		Log.d(TAG, "getPinValue - tickIndex", String.valueOf(tickIndex));
		Log.d(TAG, "getPinValue", String.valueOf(pinValue));

		return Integer.toString(pinValue);
	}
});

Hope it helps.

it makes the start from 0?
rangebar.setPinTextListener(new RangeBar.OnRangeBarTextListener() {
@OverRide
public String getPinValue(RangeBar rangeBar, int tickIndex) {
int pinValue = Math.round((float) rangebar.getTickInterval() * (tickIndex+1));

           // Log.d(d, "getPinValue - tickIndex", String.valueOf(tickIndex));
           // Log.d(d, "getPinValue", String.valueOf(pinValue));
            //range_value.setText(String.valueOf(rangebar.getTickInterval()));
            return Integer.toString(pinValue);
        }
    });

*(tickIndex+1)); this helped me

@pasaneramusugoda Your solution doesn't work with for example:
min: 100000, max: 1000000000
It gives:
getPinValue - tickIndex: 999900032

The correct answer is: shubham192's solution