Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Binding to a DrawerLayout

$
0
0

I've been trying to bind data to a drawerlayout over the past few days with no luck (and lots of flailing around as you can see from some other posts). I think my issue is the binding of the data and making sure that I have the correct parameters in the right sport. The code is below. For the purposes of this code, I have an array of items that I load from Resources.Array.NavigationItems. Once I have this in a string array, I iterate through the list, create a dictionary with an item, which is the text to be displayed, and an image, which is the image that I want to display. At this time, the image is just load from my resources's drawables. I then create two arrays. These two arrays should map to the necessary from (data in the javalist) and to (the id of the controls to display. When I run the code below, I get the error shown below the code. I am assuming that I have something wrong with my dictionary definitions. Suggestions are appreciated.

        _navigationItems = Resources.GetStringArray(Resource.Array.NavigationItems);

        var mList = new List<IDictionary<string, object>>(); 
        for(int i=0;i<_navigationItems.Length;i++){
            var hm = new Dictionary<String,Object>();
            hm.Add("item", _navigationItems[i]);
            hm.Add("image", Resource.Drawable.aniswath);
            mList.Add(hm);
        }
        var fromH = new string[]{ "item", "image" };
        var toH = new int[] { Resource.Id.title, Resource.Id.icon };

        _drawerList.Adapter = new SimpleAdapter (this, mList, 
            Resource.Layout.custom_drawer_item, fromH, toH);

Error message determined from monitor:

04-11 21:40:50.022: E/AndroidRuntime(2515): java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map 04-11 21:40:50.022: E/AndroidRuntime(2515): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:147) 04-11 21:40:50.022: E/AndroidRuntime(2515): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>