alexrainman / SegmentedControl

MIT License
86 stars 38 forks source link

Setting SelectedSegment to -1 to clear selection throws error in Android #61

Closed Welchen closed 7 years ago

Welchen commented 7 years ago

Trying to clear the selection of the SegmentedControl by passing in -1. It works in iOS but in Android it throws an exception of: "Object reference not set to an instance of an object."

Stack Trace: at SegmentedControl.FormsPlugin.Android.SegmentedControlRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x000b0] in :0 at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:136 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:380 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.BindableObject+SetValueFlags attributes, System.Boolean silent) [0x000f4] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:589 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.BindableObject+SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:386 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0005f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:539 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:83 at SegmentedControl.FormsPlugin.Abstractions.SegmentedControl.set_SelectedSegment (System.Int32 value) [0x00000] in <275342d65e084ebeb6399fcae55a3529>:0

I haven't fully looked into what is the issue but I believe it might be:

     var option = (RadioButton)nativeControl.GetChildAt(Element.SelectedSegment);
apoorvvw commented 7 years ago

I'm having the same issue.

alexrainman commented 7 years ago

Releasing a fix today.