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. View.setEnabled() Deprecated?

I'm working with 2.0 and in my xml layout, I changed the Enabled
property of a Button, only to see that that is Deprecated. Eclipse
property manager tells me (when I mouse over the property) :
"Deprecated use state_enabled instead."

So sure I can set state_enabled in the xml layout, but how to do it
programatically? Can it be done? I'd like the button to be disabled
initially and then become enabled depending on user action. How can
this be done without using the deprecated method????

Frankly I'm completely at a loss as to how to set any and all xml
attributes programatically. It seems some have matching properties in
the Java objects and some do not. Some can be set by using
LayoutParams and some cannot. Please help.

Thanks.

-- 

2. Media controller problem

Hi all,

I have written a small media player application. I tried to play all
the audio files (android supported media files). .mid, .mp3 files are
playing well with showing MediaController.

But when I tried to play .ogg file, I got the following exception.

W/WindowManager(   74): Requested window null does not exist

W/WindowManager(   74): java.lang.RuntimeException

W/WindowManager(   74):         at
com.android.server.WindowManagerService.windowForClientLocked
(WindowManagerService.java:7767)

W/WindowManager(   74):         at
com.android.server.WindowManagerService.addWindow
(WindowManagerService.java:1191)

W/WindowManager(   74):         at com.android.server.WindowManagerService
$Session.add(WindowManagerService.java:5513)

W/WindowManager(   74):         at android.view.IWindowSession$Stub.onTransact
(IWindowSession.java:74)

W/WindowManager(   74):         at com.android.server.WindowManagerService
$Session.onTransact(WindowManagerService.java:5485)

W/WindowManager(   74):         at android.os.Binder.execTransact(Binder.java:
287)

W/WindowManager(   74):         at dalvik.system.NativeStart.run(Native
Method)

W/WindowManager(   74): Attempted to add window with token that is not
a window: null.  Aborting.

I/MediaPlayerDemo(  724):android.view.WindowManager$BadTokenException:
Unable to add window -- token null is not valid; is your activity
running?



Basically I want to show a media controller while playing a audio
file. It is working fine for some media formats (.mp3 , .mid), I mean
able to show the media controller while playing. But when I tried to
play .ogg file, I got the above error.



Can any one please help me to solve this.

-- 

3. getting Contact data into the Emulator

4. ListView dividerHeight="1dip" appearance on Droid

5. How to installmy apk in my device G1???

6. International emergency number support

7. SQLiteOpenHelper