[mono-android] problem with a Javalist (ArrayAdapter)
John Murray
john at murray.gb.com
Thu Jan 5 12:41:05 EST 2012
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: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Jonathan Pryor
Sent: 05 January 2012 15:52
To: john at murray.gb.com; 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
Monodroid at lists.ximian.com
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
More information about the Monodroid
mailing list