Need help with a custom Spinner/ArrayAdapter setup
Posted
by
MisterSquonk
on Stack Overflow
See other posts from Stack Overflow
or by MisterSquonk
Published on 2010-12-29T02:50:40Z
Indexed on
2010/12/29
2:53 UTC
Read the original article
Hit count: 214
android
|arrayadapter
I have a WeatherSpinner class which extends Spinner. The class shows region names which I originally did using an ArrayAdapter<String>
but I now want to use ArrayAdapter<Locale>
(Locale is an abstract 'empty' class of my own).
I'm getting a ClassCastException
when trying to populate my ArrayAdapter with the following...
protected ArrayList<?> theList;
protected ArrayAdapter<Locale> aa = null;
...
protected void updateContents(ArrayList<?> list, int selectedItem) {
theList = list;
// Exception thrown on next line
aa = new ArrayAdapter<Locale>(theContext, android.R.layout.simple_spinner_item,
(Locale[]) theList.toArray());
...
}
I'm passing a RegionList
object into updateContents() as the 'list' parameter and RegionList extends ArrayList<Region>
, and Region extends Locale
. I've also overriden Region's toString()
method to return a valid String.
What am I not seeing here? Am I wrong about the way ArrayList<?>.toArray()
works?
© Stack Overflow or respective owner