Need help with a custom Spinner/ArrayAdapter setup
- by MisterSquonk
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?