Well, I found the XML attribute android:visibility="gone" to make a
hidden field so I can pass the code around... but I'm still wondering
if there's a better way to do what I'm attempting.

I still have the problem of how to pre-select it the next time the
spinner is visible without iterating through all the values to
determine which one is at the index I want to select.

On Dec 17, 11:17 am, filbert <filbert...@gmail.com> wrote:
> I'm trying to set up a preferences page using a data driven Spinner.
> I've searched around and looked at some tutorials, but they all seem
> to be much simpler examples.
>
> The data in my table looks like this:
> - id (primary key)
> - description (user friendly description of the option)
> - code (int representation of the option)
>
> I only want the Description to appear in the spinner, so the spinner
> item layout XML just has a TextView for the description.  I'm using a
> SimpleCursorAdapter to populate the spinner.
>
> I need to get the code for the selected item so I can pass it to a web
> service.
>
> When the user selects an option, I can do one of these:
> getSelectedItem() - Gets the object? that was selected - what object
> would this be?  The TextView?
> getSelectedItemPosition() - Gets the location in the list of the
> selected item.
> getSelectedItemId() - Gets the id of the object - is this the same as
> the DB id?  Or is it an android resource id?
> getSelectedView() - Gets the view of the selected Item, which in this
> case is a TextView
>
> Ideally, I'd like to be able to get the code right away and not have
> to mess with indexes or ids.  In HTML you specify a value for each
> dropdown item and only the selected item is submitted in the post.
> Can you do something like this in Android?  Is there a way to
> associate the code in a "hidden" view or something like that?
>
> Or can I get the DB id and look up the code?  Somehow it doesn't seem
> right that I would have to look up the code based on the description
> or worse yet, have to count the rows based on the selected Index to
> determine which item it is...
>
> In a related problem, once I've saved their preference, I want to be
> able to default the spinner value the next time they see it.  I can
> use spinner.setSelection(index) but that assumes I know what the index
> is... but all I know is the id or code that I saved in the
> preferences.  I don't want to save the index in the preferences b/c
> that just seems like poor app design in case the data changes.
>
> Any help would be appreciated.
>
> I can post the code if I'm not making sense...
--~--~---------~--~----~------------~-------~--~----~
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-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to