Thanks Jonathon I knew it had something to do with a strict declaration - I just wasn't sure how I should do the cast Didn't know I could declare it as a javalist - I was trying all kinds of things like Java.Utils.Arrays etc
I've got it going now - Many many thanks John Murray -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jonathan Pryor Sent: 05 January 2012 15:52 To: [email protected]; Discussions related to Mono for Android Subject: Re: [mono-android] problem with a Javalist (ArrayAdapter) On Jan 5, 2012, at 9:36 AM, John Murray wrote: > The array is a list of list thus List<List<string>>() Is it really a List<List<string>>? Conceptually, sure, but actually? > So I come to the click handler and want to extract the 'Keyno' from the array of the line selected > > I've got this code > private void loglist_ItemClick(object sender, ItemEventArgs e) > { > int pos = Convert.ToInt32(e.Id); > var selitem = loglist.Adapter.GetItem(pos); What is the type of `loglist`? Of `loglist.Adapter`? Are you providing your own Adapter (by e.g. subclassing BaseAdapter), or are you using e.g. ArrayAdapter<T>? `selitem` is very probably a Java.Lang.Object, as that's what BaseAdapter.GetItem(int) returns. > var selitem2 = selitem.ToArray<string>(); > string sel2 = selitem2.ElementAt(0).ToString(); > > Sorry about the various selitems I've been trying everything - the debugger tells me that the selitem is a JavaList The debugger knows about the runtime types involved. The compiler does not. It sounds like you might be misunderstanding `var`. Your statement: var selitem = loglist.Adapter.GetItem(pos); is treated identically by the compiler as: Java.Lang.Object selitem = loglist.Adapter.GetItem(pos); `var` is not `dynamic`. :-) If `selitem` is a JavaList, and you want to grab elements from it, cast it: JavaList selitems = (JavaList) loglist.Adapter.GetItem(pos); string sel2 = selitems[0].ToString(); Thanks, - Jon _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
