material-range-bar icon indicating copy to clipboard operation
material-range-bar copied to clipboard

Pin value for string length greater than 4 is not giving the correct value

Open shubhams opened this issue 7 years ago • 2 comments

I set the tickEnd and tickStart values as:

rangeBar.setTickEnd(10000);
rangeBar.setTickStart(1000);
rangeBar.setTickInterval(1000);

Now, to get the pin values I was using the setOnRangeBarChangeListener. The left pin value was coming out to be correct as 1000, however the right pin value was also coming out to be 1000.

So, I peeked into the method of getPinValue(int tickIndex) and I noticed that before returning the value, mPinTextFormatter is used to format the pin value. The mPinTextFormatter is defined as:

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

The if condition to check if length is greater than 4, returns the substring upto the length 4.

Although I fixed the issue by setting by own PinTextFormatter that returns the string value as it is, and it might make sense to return the "substring" when showing the value in the pin bubble.

However, a simple rangeBar.getRightPinValue() would also give the wrong value in this case.

shubhams avatar Jun 03 '17 07:06 shubhams

<com.appyvet.rangebar.RangeBar xmlns:custom="http://schemas.android.com/apk/res-auto" android:id="@+id/rangebar1" android:layout_width="match_parent" android:layout_height="72dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" custom:pinMaxFont="10sp" custom:selectorBoundaryColor="@color/accent" custom:selectorBoundarySize="2dp" custom:selectorSize="10dp" custom:temporaryPins="false" custom:tickEnd="80000" custom:tickInterval="1000" custom:tickStart="1000"/> not working

shreyan007 avatar Jun 05 '17 12:06 shreyan007

You can do it programmatically, like this:

rangeBar.setPinTextFormatter(new RangeBar.PinTextFormatter() {
            @Override
            public String getText(String value) {
                return value;
            }
        });

shubhams avatar Jun 05 '17 18:06 shubhams