mail-archives/monodroid/2011-December/007765.html

116 строки
5.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [mono-android] System.NotSupportedException with ArrayAdapter of custom object
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20System.NotSupportedException%20with%20ArrayAdapter%0A%09of%20custom%20object&In-Reply-To=68573476-2E56-4D75-AD65-8DBC314B2E58%40xamarin.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="007755.html">
<LINK REL="Next" HREF="007780.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[mono-android] System.NotSupportedException with ArrayAdapter of custom object</H1>
<B>Jared Barneck</B>
<A HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20System.NotSupportedException%20with%20ArrayAdapter%0A%09of%20custom%20object&In-Reply-To=68573476-2E56-4D75-AD65-8DBC314B2E58%40xamarin.com"
TITLE="[mono-android] System.NotSupportedException with ArrayAdapter of custom object">rhyous at yahoo.com
</A><BR>
<I>Mon Dec 12 23:08:46 EST 2011</I>
<P><UL>
<LI>Previous message: <A HREF="007755.html">[mono-android] System.NotSupportedException with ArrayAdapter of custom object
</A></li>
<LI>Next message: <A HREF="007780.html">[mono-android] System.NotSupportedException with ArrayAdapter of custom object
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7765">[ date ]</a>
<a href="thread.html#7765">[ thread ]</a>
<a href="subject.html#7765">[ subject ]</a>
<a href="author.html#7765">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>&gt;&gt;<i> I am getting this error too. The documentation states this should work.
</I>
&gt;&gt;<i> <A HREF="http://docs.monodroid.net/index.aspx?link=T%3aAndroid.Widget.ArrayAdapter">http://docs.monodroid.net/index.aspx?link=T%3aAndroid.Widget.ArrayAdapter</A>
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> I have created a very simple sample project that duplicates this issue.
</I>&gt;&gt;<i> <A HREF="http://www.rhyous.com/wp-content/uploads/2011/12/TestCustomObjectInArrayAdapter.zip">http://www.rhyous.com/wp-content/uploads/2011/12/TestCustomObjectInArrayAdapter.zip</A>
</I>&gt;<i>
</I>&gt;<i>I'm sorry, this is: <A HREF="http://bugzilla.xamarin.com/show_bug.cgi?id=2347">http://bugzilla.xamarin.com/show_bug.cgi?id=2347</A>
</I>
Thanks for logging the bug, Jon.&#160;I went ahead and used ArrayAdapter&lt;String&gt;.&#160;Then for my DeviceList, I created this extension method that just takes the value I wanted to display as a string in my list.
&#160; &#160; &#160; &#160; // Extension method
&#160; &#160; &#160; &#160; public static String[] Names(this DeviceList inList)
&#160; &#160; &#160; &#160; {
&#160; &#160; &#160; &#160; &#160; &#160; string[] deviceList = new string[inList.count];
&#160; &#160; &#160; &#160; &#160; &#160; for (int i = 0; i &lt; inList.count; i++)
&#160; &#160; &#160; &#160; &#160; &#160; {
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; deviceList[i] = inList.Devices[i].DeviceName;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; return deviceList;
&#160; &#160; &#160; &#160; }
Then here is the first part of my DeviceArrayAdapter where you see what I did.
&#160; &#160; public class DeviceNameArrayAdapter : ArrayAdapter&lt;String&gt;
&#160; &#160; {
&#160; &#160; &#160; &#160; DeviceList _DeviceList;
&#160; &#160; &#160; &#160; private int mResID;
&#160; &#160; &#160; &#160; public DeviceNameArrayAdapter(Context c, int resID, DeviceList inDeviceList)
&#160; &#160; &#160; &#160; &#160; &#160; : base(c, resID, inDeviceList.Names())
&#160; &#160; &#160; &#160; {
&#160; &#160; &#160; &#160; &#160; &#160; mResID = resID;
&#160; &#160; &#160; &#160; &#160; &#160; _DeviceList = inDeviceList;
&#160; &#160; &#160; &#160; }
&#160; &#160; ....
It seems to be a good workaround for me, so I thought I would share it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <A HREF="http://lists.ximian.com/pipermail/monodroid/attachments/20111212/fa117987/attachment.html">http://lists.ximian.com/pipermail/monodroid/attachments/20111212/fa117987/attachment.html</A>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="007755.html">[mono-android] System.NotSupportedException with ArrayAdapter of custom object
</A></li>
<LI>Next message: <A HREF="007780.html">[mono-android] System.NotSupportedException with ArrayAdapter of custom object
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7765">[ date ]</a>
<a href="thread.html#7765">[ thread ]</a>
<a href="subject.html#7765">[ subject ]</a>
<a href="author.html#7765">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/monodroid">More information about the Monodroid
mailing list</a><br>
</body></html>