Found the source of the problem and the solution.
1. android.R.id.text1 is predefined UI element for Spinner control and
should be used in 'to' array
2. In this case (using SimpleCursorAdapter) cursor MUST have '_id'
field. If you get data from SQL database and use raw SQL query, it
possible to use the next statement:
SELECT Product_ID AS _id ...
On Oct 28, 9:52 am, gin_tonic <[email protected]> wrote:
> Hello,
>
> I'm trying to create a very simple application that extract data from
> SQL database and populate a spinner control with (for example) product
> names.
> I found the following example of the code:
>
> String[] from = new String[] { "Product_Name" };
>
> int[] to = new int[] { android.R.id.text1 };
>
> SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
> android.R.layout.simple_spinner_item, product_cursor, from, to );
>
> adapter.setDropDownViewResource
> (android.R.layout.simple_spinner_dropdown_item);
>
> spinner.setAdapter(adapter);
>
> The only thing I couldn't understand what should I put into "to"
> array? The spinner is the only control on the form. I tried to find
> the answer, but most of the samples use ListView control and put
> "android.R.id.text1" into "to" array
>
> Thanks,
> gin_tonic
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en