The issue is that you're trying to cast *the array* whereas you intent was probably to cast *each element of the array*.

You could try this:

for (Camera.Size size : cameraSizeList) {
stringArray.add(size.toString());
}

... etc....

Or you could combine the arrays into one Object[] array. The adapter would then call toString on each Object inside the array.

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ArrayAdapter.java#L389

But if you do that, you won't be able to refer to objects in the array and know their types (which may be useful), unless you used "instanceof".

To keep type information, you could implement wrappers for your objects that have a common base class (or interface), overriding toString() for binding, and implementing other methods that would do stuff specific to your application logic.

-- K

29.03.2012 15:21, Jim Graham написал:
While working on my current app, I find myself needing to populate
a spinner (and a MultiSpinner, but that one's easy---feed it the
list directly) from data that's stored in various types of Lists
(List<String>, List<Integer>, List<Camera.Size>, and probably
List<int[]>).

So far, I've read all kinds of stuff about the ArrayList type, and
when I search for List<x>  I get ArrayList<x[]>  instead.  I THOUGHT
I had the solution, using

    String[] foo = bar.toArray();

Eclipse threw an error, and required me to cast that to String[] as:

    String[] foo = (String[]) bar.toArray();

And this caused a force close, where the error stated that you can't
cast toArray() to String[].

I've gone through multiple searches through this list, Stack Overflow,
XDA, google, books and e-books on both Android and Java in general, and
have yet to find anything that works.  If I can just successfully (i.e.,
without a force close) get that List<x>  to x[] (where 'x' is String,
Integer, etc.), I could then feed that to the ArrayAdapter and "feed"
the Spinner.

Could someone help me out with that, please?  I'm sure that toArray()
is part of the answer, but I haven't found a working example, and my
(mis) understanding of it was clearly wrong.

Thanks,
    --jim


--
Kostya Vasilyev

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to