SimpleCursorAdapter and Spinner control

by gin_tonic » Thu, 29 Oct 2009 14:42:49 GMT


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

--~--~---------~--~----~------------~-------~--~----~



SimpleCursorAdapter and Spinner control

by gin_tonic » Fri, 06 Nov 2009 06:47:06 GMT


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




--


Sponsored Links


Other Threads

1. Save onDraw canvas

I want to to animation as follows. The first call of onDraw, I will
draw the scene. Subsequent times, I want to translate the scene, by
doing canvas.translate(dx, dy), but the canvas returned by onDraw is
always blank. Thus, I have to redraw the whole scene again.

public void onDraw(Canvas canvas){
canvas.translate(dx, dy);
drawScene(canvas);
}
 Is there anyway I can save the scene drawn on to canvas from the
first time so that subsequent times, I just need to translate? This
will improve performance significantly.
Thanks
--~--~---------~--~----~------------~-------~--~----~

2. playing a video stream created by vlc on android?

Hi,

I saw this post on the adroid-developers list:

3. Can't display GoogleMaps in application

4. Problem: Holding the Home button, and powering on the device doesn't send me into recovery mode.

5. Set Background color for custom dialog title ??

6. streaming video / remote rendering sample?

7. Wed service