Thursday, March 29, 2012

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

On Thu, Mar 29, 2012 at 03:37:19PM +0400, 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,
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.

The idea here is to use one spinner for all of the settings types.
That one spinner will be reloaded depending on the type of settings
the user is working with (selected from a ListView). Having spinners
for ALL of the settings works fine on my tablet, but would have to be
so tiny on a phone it'd be impossible to use. So, the user selects
one settings mode, the spinner is reloaded, and the user makes their
choice. Then, ohItemClicked responds accordingly for the settings
type currently in effect.

A MultiSpinner (spinner with checkboxes instead of radiobuttons) will
handle options where more than one can apply. But that one's easy---you
just load it directly from a List<>.

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

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

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

Thanks,
--jim

--
THE SCORE: ME: 2 CANCER: 0
73 DE N5IAL (/4) | DMR: So fsck was originally called
spooky130u@gmail.com | something else.
< Running FreeBSD 7.0 > | Q: What was it called?
ICBM / Hurricane: | DMR: Well, the second letter was different.
30.44406N 86.59909W | -- Dennis M. Ritchie, Usenix, June 1998.

Android Apps Listing at http://www.jstrack.org/barcodes.html

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

No comments:

Post a Comment