[mono-android] System.NotSupportedException with ArrayAdapter of custom object

Jared Barneck rhyous at yahoo.com
Mon Dec 12 23:08:46 EST 2011


>> I am getting this error too. The documentation states this should work.

>> http://docs.monodroid.net/index.aspx?link=T%3aAndroid.Widget.ArrayAdapter
>> 
>> I have created a very simple sample project that duplicates this issue.
>> http://www.rhyous.com/wp-content/uploads/2011/12/TestCustomObjectInArrayAdapter.zip
>
>I'm sorry, this is: http://bugzilla.xamarin.com/show_bug.cgi?id=2347


Thanks for logging the bug, Jon. I went ahead and used ArrayAdapter<String>. Then for my DeviceList, I created this extension method that just takes the value I wanted to display as a string in my list.


        // Extension method
        public static String[] Names(this DeviceList inList)
        {
            string[] deviceList = new string[inList.count];
            for (int i = 0; i < inList.count; i++)
            {
                deviceList[i] = inList.Devices[i].DeviceName;
            }
            return deviceList;
        }

Then here is the first part of my DeviceArrayAdapter where you see what I did.

    public class DeviceNameArrayAdapter : ArrayAdapter<String>
    {
        DeviceList _DeviceList;
        private int mResID;

        public DeviceNameArrayAdapter(Context c, int resID, DeviceList inDeviceList)
            : base(c, resID, inDeviceList.Names())
        {
            mResID = resID;
            _DeviceList = inDeviceList;
        }
    ....

It seems to be a good workaround for me, so I thought I would share it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monodroid/attachments/20111212/fa117987/attachment.html 


More information about the Monodroid mailing list