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. onContextItemSelected does not respond

Hello,

I am creating a context menu in separate class from the listview,
because the contextmenu will be access by several listviews in
different classes.
Whenever I long-click the listview, contextmenu pops up, but nothing
happens when the options were chosen.
Tried to look at logcat message and it said something like this:

Window already focused, ignoring focus gain of:
com.android.internal.view.iinputmethodclient$stub$pr...@43c488f8

Any idea what really causing this problem?
cause it works perfectly fine if i put the contextmenu on the same
class as listview.


Thanks

-- 

2. No resource found that matches the given name (at 'entries' with value '@arrays/items').

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
<ListView
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:entries="@arrays/items"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
</ListView>
</RelativeLayout>

This is returning the following error...
error: Error: No resource found that matches the given name (at
'entries' with value '@arrays/items').

please help me cuz i am trying to design this ui for my project.. and
i can't really do anything more untill this is solved
thank you

-- 

3. how can i write a Broadcast Receiver that will be invoked when user clicks on any application icon.

4. Android Resources for Application development

5. Status of build using jdk 1.6?

6. Passing surface to native

7. Audio Processing