Hello,

I am trying to connect a AutoCompleteTextView with a
SimpleCursorAdapter, which narrows down the selection of a list of
words, when the user starts typing.

Following some other posts here, I've come up with the following code,
but it doesn't work. I defined a FilterQueryProvider runQuery() method
for the SimpleCursor Adapter, but when I use the debugger in the code,
the response from the ContentResolver.query((0 method call is null.

I think the problem is that there is no relationship between the
CONTENT_URI and the SQL database, but I can't be sure.

Can someone please help?

Paul

               public static final String AUTHORITY =
"com.A.android.examples";
               public static final Uri CONTENT_URI = Uri.parse
("content://" + AUTHORITY +  "/sqlautocomplete");

               <snip> code to fill the SQL Cursor from a list of words
</snip>

                mContentResolver = this.getContentResolver();
                AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.edit);

                mFrom = new String[] { DictionaryDbAdapter.KEY_ROWID};
                mTo = new int[] { android.R.id.text1 };
                SimpleCursorAdapter adapter = new SimpleCursorAdapter
( this,
                                        
android.R.layout.simple_dropdown_item_1line,
                                        aCursor, mFrom, mTo );

                // Define the CursorToString class
                adapter.setCursorToStringConverter(new
DictionaryCursorConverter());

                // Define the SQL query
                adapter.setFilterQueryProvider(new FilterQueryProvider
()
                {
                        @Override
                        public Cursor runQuery(CharSequence
constraint)
                        {
                          StringBuilder buffer = null;
                          String[] args = null;
                          if (constraint != null)
                          {
                            buffer = new StringBuilder();
                            buffer.append("UPPER(");
                            buffer.append(mFrom[0]);
                            buffer.append(") GLOB ?");
                            String filter = constraint.toString
().toUpperCase() + "*";
                            args = new String[] { filter };
                          }

                          Cursor aResult = mContentResolver.query
(CONTENT_URI,
                                                       mFrom,
                                                        buffer == null ? null :
                                                        buffer.toString(), args,
                                                        "ASC");
                          return aResult;
                        }
                } );

                // Connect the adapter to the auto-complete text view
                textView.setAdapter(adapter);

I implemented the CursorToStringConverter class as follows:

                public class DictionaryCursorConverter implements
CursorToStringConverter
                {
                  @Override
                 public CharSequence convertToString(Cursor
theCursor)
                 {
                   // Return the first column of the database cursor
                   String aColumnString = theCursor.getString();
                   return aColumnString;
                 }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to