I’m trying to cast a spinner.SelectedItem to string in monodroid.
Since SelectedItem is a Java.Lang.Object, I need to know how can I cast a Java.Lang.Object to a native .net type.
Thank you,
Alex
I’m trying to cast a spinner.SelectedItem to string in monodroid. Since SelectedItem is a
Share
You didn’t provide any context into what you’re binding to the spinner, but I’m assuming it’s just a list of strings? If that’s the case, one possibility is to just do
That won’t be very useful if the underlying object is not a string, though. You have some other options available as well. You can use spinner.SelectedItemPosition to get the item out of the spinner adapter’s source. Something like:
You could also do:
It all depends on what you’re trying to do and when. Xamarin has a tutorial up here that goes through the basics of using a spinner.