Thursday, March 29, 2012

Re: [android-developers] populating a Spinner with various types of List class

Ray Tayek wrote:
At 04:21 AM 3/29/2012, you wrote:
>...  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. ...

list.toArray(new String[0])


From the API docs for 'toArray(T[] a)':
ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this list

The OP's original list variable was 'bar' but they never told us the type of that variable. What they said was:

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

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

If 'bar' is of type 'String[]' then, of course, your tip will work perfectly.

-- 
Lew


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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate