Forum Xamarin.Android

Trying to convert Shared Preferences into Dictionary.

JPHochbaumJPHochbaum USMember ✭✭✭

I am getting specified cast is not valid when trying to cast my sharedPref into a Dictionary. I want to iterate my Shared Pref and populate my Spinner. If there is another way to do this please advise thanks!

public Dictionary<string, object> favoritesDict = new Dictionary<string, object>(); this.favorites = Application.Context.GetSharedPreferences("Favorites", FileCreationMode.Private); this.favoritesDict = (Dictionary<string, object>)this.favorites.All; foreach(KeyValuePair<string, object> kvp in this.favoritesDict) { this.listFaves.Add(Convert.ToString(kvp.Value)); } //Fill listFaves.. this.spinnerAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, this.listFaves);

Best Answer


Sign In or Register to comment.