question

njsokalski avatar image
0 Votes"
njsokalski asked LeonLu-MSFT commented

RangeSlider Not Updated After Setting Values

I have the following method that I use to update my com.google.android.material.slider.RangeSlider view (the values assigned to ValueFrom, ValueTo, Values[0] & Values[1] are actually calculated, I just have literals here for simplicity, but I have confirmed that my calculated values are correct):

 private void UpdateDisplayedRangeSlider()
 {
     //Remember current values
     int currminvalue = this.rsDisplayedValues.Values[0].IntValue();
     int currmaxvalue = this.rsDisplayedValues.Values[1].IntValue();
     //Temporarily set values to 0
     this.rsDisplayedValues.Values[0] = (Java.Lang.Float)0f;
     this.rsDisplayedValues.Values[1] = (Java.Lang.Float)0f;
     //Update ValueFrom/ValueTo
     this.rsDisplayedValues.ValueFrom = (Java.Lang.Float)-100f;
     this.rsDisplayedValues.ValueTo = (Java.Lang.Float)100f;
     //Set new selected values
     this.rsDisplayedValues.Values[0] = (Java.Lang.Float)-50f
     this.rsDisplayedValues.Values[1] = (Java.Lang.Float)50f
 }

When the values are updated, the RangeSlider does not show the changes (the properties have the correct values, but the thumbs do not move). This is my first time using the RangeSlider (or any of the Slider views). Is there something else I need to do to display the new values?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

You can use setValues to set selected values. So I change your UpdateDisplayedRangeSlider method like following code. I tried to use this.rsDisplayedValues.Values[0], I get the same result as yours, it not work.

private void UpdateDisplayedRangeSlider()
        {
            //Remember current values
            int currminvalue = this.rsDisplayedValues.Values[0].IntValue();
            int currmaxvalue = this.rsDisplayedValues.Values[1].IntValue();
            //Temporarily set values to 0
            Float[] values1 = { (Float)(0f), (Float)(0f) };
           this.rsDisplayedValues.SetValues(values1);

           
            //Update ValueFrom/ValueTo
            this.rsDisplayedValues.ValueFrom = -100f;
            this.rsDisplayedValues.ValueTo =100f;


            //Set new selected values
           Float[] values = { (Float)(-50.0f), (Float)50.0f };
           this.rsDisplayedValues.SetValues(values);

        }




Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks! Using SetValues seems to have fixed it! Just out of curiosity, when you said

I get the same result as yours, it not work.

did you actually mean "I get the same result as yours, it now work."?

0 Votes 0 ·

No. Using this.rsDisplayedValues.Values[0] is not working, but I use rsDisplayedValues.SetValues(values); is working.

0 Votes 0 ·