Spooky wrote:
>
> Kostya Vasilyev wrote:
> > The issue is that you're trying to cast *the array* whereas you
> > intent was probably to cast *each element of the array*.
>
> I was just trying to directly convert the List (in this case,
>
"I was just trying ..." implies that the rules of Java should accommodate 
your programming instead of the other way around.

Java doesn't let you cast across type hierarchies. Thus, you cannot cast 
'Camera.Size' to 'String', nor can you cast 'Camera.Size[]' to 'String[]'.

You might find the Java tutorials informative.
 

> List<String>) to an array of strings (String[]).  I hadn't gotten
> as far as the other settings types yet---just preparing for them
> when I get to them.
>
> ... 

> > You could try this:
> > 
> > for (Camera.Size size : cameraSizeList) {
> > stringArray.add(size.toString());
> > }
> > 
> > ... etc....I was hoping for a direct conversio for each List to each 
> respective
> array, but I'm starting to think that might not be ideal, after all.
>
> > Or you could combine the arrays into one Object[] array. The adapter
> > would then call toString on each Object inside the array.
>
> Again, multiple arrays, not one.
>
Again, he's just making suggestions. Again.
 

> > 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".
>
> I've already got that covered.  :-)   A simple switch() in onItemClicked
> will determine which type of settings are in effect, and respond
> accordingly.
>

Switching on types is an antipattern in O-O programming. Polymorphism, will 
do that switch for you.
 

> > 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.
>
> I'm afraid that's far above my level at this point (let's put it this
> way, I was debating on whether to post this in this list or the
> android-for-beginners list).  I'm still not sure whether that list
>
The right answer remains the right answer regardless of your level. Maybe 
you should rise to the level that you can use this suggestion.
 

> would have been more appropriate (in other words, did I ask yet another
> beginner-level question here, or was it more at an intermediate level?).
>
> Either way, I can use the example you showed above, and I think that'll
> work for me.
>
The wrapper approach is one way but I normally use the simple array-copy 
technique. Why are you so afraid of that loop?

 List<String> choices = new ArrayList<String>(sizes.size());
 for (Camera.Size size : sizes )
 {
   choices.add(size.toString());
 }

-- 
Lew
 

-- 
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