Problem with AutoCompleteTextView and SimpleCursorAdapter

by class_java » Tue, 03 Mar 2009 06:19:52 GMT

Sponsored Links
 Hi All,

I have a AutoCompleteTextView and I wont in the drop down list that
appears while typing to contain data from a database through
SimpleCursorAdapter. The drop down list appears, but there is not text
in it. When I click in the drop down item seems to work fine, the Text
is correctly shown in the AutoCompleteTextView. Please help...

Code samples:
 final AutoCompleteTextView editTxt = (AutoCompleteTextView)

        mDbHelper = new DbHelper(this);

        Cursor cursor = mDbHelper.fetchAll();
        int[] to = new int[]{android.R.layout.select_dialog_item};
        SimpleCursorAdapter cursAdapt = new SimpleCursorAdapter
(this,android.R.layout.simple_dropdown_item_1line,cursor,new String[]
        cursAdapt.setCursorToStringConverter(new CursorConverter());

<?xml version="1.0" encoding="utf-8"?>

<TextView  xmlns:android="" ;

public class CursorConverter implements CursorToStringConverter{

        public CharSequence convertToString(Cursor cursor) {
         String a = cursor.getString(1);
         return a;


Thanks in advance...


Problem with AutoCompleteTextView and SimpleCursorAdapter

by Will » Wed, 04 Mar 2009 02:03:05 GMT

 I haven't done one of these with a SimpleCurosrAdapter, but I've
worked through it with a Cursor/CursorAdapter.  I just uploaded to the
Developers group what I think is the minimum code for an AutoComplete
with a Cursor/CursorAdapter.

It's here:  

Sponsored Links

Problem with AutoCompleteTextView and SimpleCursorAdapter

by Tseng » Wed, 04 Mar 2009 06:24:21 GMT

 ou don't have to create your own XML file if you're just want to
display a one-liner dropdown menu. Instead better to use the already
defined one in the android resources. Basically you can leave the
auto_complete.xml, as it's not used anyways in your code (unless you
want to design your own dropdown list views).

Basically there are two reasons:
1. You haven't set the color states correctly so the text color =
background color
2. You have selected a wrong id in the "to" parameters

In your example, the latter seems to be the case.

you're using an layout id as "to". This is wrong. You have to use the
ID of the textfield in which your data belongs.

For example you have to data fields in your cursor, lets say

new String[] { DbHelper.FOOD_NAME, DbHelper.FOOD_PRICE }

Now if you have an layout file, with 2 TextView elements called
foodname and foodprice, you'd have to make the "to" part as follows
new int[] {,} in exactly this order. First
element of from (DbHelper.FOOD_NAME) will be placed in the view with
the first ID from "to" (in this case:

Since you're using the predefined android layout for the dropdown list
(android.R.layout.simple_dropdown_item_1line), the (only) textview
item is called

So changing
int[] to = new int[]{android.R.layout.select_dialog_item};
SimpleCursorAdapter cursAdapt = new SimpleCursorAdapter
(this,android.R.layout.simple_dropdown_item_1line,cursor,new String[]


int[] to = new int[]{};
SimpleCursorAdapter cursAdapt = new SimpleCursorAdapter
(this,android.R.layout.simple_dropdown_item_1line,cursor,new String[]

should do the trick. You HAVE to use, because this
is the id which was set in android sdks \res\layout
\simple_dropdown_item_1line.xml file.

This is btw the case for all default android layout files. They have
no fixed names, instead it's always to or to in
case of buttons (i.e. in default Dialog layouts)

On Mar 2, 10:49pm, class_java <> wrote:

Other Threads

1. prevent native application


I want to prevent native application to receive message.I want that my
application only receive message. Is it possible ? if yes then how ?
can i access the received message and delete it ?

2. Launching a service from a TabActivity

Dear all,

I'd like to start a service from a tabactivity (I first tried in the
activity launched for a tab but it seems taht there is a technical

So inside my TabActivity I defined a method named startService() which
is quite simple :

But I have an error (in logcat) telling that the service can't be
started since it is not found :

08-04 12:14:28.476: WARN/ActivityManager(564): Unable to start service
Intent { (has extras) }:
not found

The point is that if I copy-past the same (Intent+start service) code
inside another standard activity, my service is found and started.

Is there any Android Guru that could help me ?

Thank you very much for your help.



3. android-build-make-error

4. Dialog

5. ACTION_GET_CONTENT audio, video

6. android.process.acore error has stopped unexpectedly

7. the user data image is used by another emulator. aborting