On May 14, 2012, at 1:12 PM, Jones wrote:
> SimpleExpandableListAdapter isn't working. I'm just getting the error message 
> from the log that there is a cast exception.

Can you provide the SimpleExpandableListAdapter use?

As a guess, try replacing Dictionary use with JavaDictionary:

        // Old:
        IList<IDictionary<string, object>> groupData = new 
List<IDictionary<string, object>>() {
                new Dictionary<string, object> { ... },
        };
        new SimpleExpandableListAdapter (this, groupData, ...);

        // New:
        IList<IDictionary<string, object>> groupData = new 
List<IDictionary<string, object>>() {
                new JavaDictionary<string, object> { ... },
        };

My suspicion is that the change is due to fixing:

        https://bugzilla.xamarin.com/show_bug.cgi?id=2147

That is, if you pass a non-Java.Lang.Object subclass to Java code, it'll get 
"wrapped" into a JavaObject (internal type), and when it comes back out from 
Java it'll be "unwrapped", thus providing reference equality: what you put in 
is what you get out.

Unfortunately this is a break from the previous behavior, which would try to 
"deep marshal" the collection types, which allowed things to work but meant 
that if you later queried for the "original" List/Dictionary/etc. you'd get 
back a completely different instance (object.ReferenceEquals() would be false).

For those who are concerned about gref counts, an alternative coding pattern is:

        using (IList<IDictionary<string, object>> groupData = new 
JavaList<IDictionary<string, object>>()) {
                using (var d = new JavaDictionary<string, object> { ... })
                        groupData.Add (d);
                new SimpleExpandableListAdapter (this, groupData, ...);
        }

The above ensures that the JavaDictionary and JavaList instances don't survive 
past the SimpleExpandableListAdapter use, whereas previously the grefs would 
stick around ~forever (or until the SimpleExpandableListAdapter instance was no 
longer used in both Java & C#).

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to