RangeSlider Not Updated After Setting Values

Nathan Sokalski 4,126 Reputation points
2022-05-05T21:20:30.53+00:00

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?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,011 Reputation points Microsoft Vendor
    2022-05-06T02:48:47.417+00:00

    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.


0 additional answers

Sort by: Most helpful