<<Unfortunately, this is not a complete worked out example. Could someone
forward me a more complete example? I've found lots of code fragments, but
no code that shows how to initialise the SimpleCursorAdapter contents, or
how it works together with the AutoCompleteTextView. >>

<There is also an example in the APi demos with the
contacts.~/android-sdk-windows-1.1_r1/samples/ApiDemos/src/com/example/android/apis/view/AutoComplete4.java>

Many thanks.



That was very helpful.



I still have a question. I have now progressed to the point where list of
entries is being displayed on the auto-complete box. However, when I try to
narrow down the displayed choice by typing text into the auto-complete text
box, the displayed list remains the same. For example, if the list initially
contains  “aaaa1”, “aaaa2”, “aabb1”, “aabb2”,  and “aacc1” and “aacc2”,
 then when I type in “aab”, I expect to see only “aabb1” and “aabb2”.
Instead all entries are still displayed.



I found this very helpful message explaining that the problem is that
SimpleCursorAdapter does not implement filtering:

http://www.mail-archive.com/android-developers@googlegroups.com/msg00546.html



The runQuery() method of the FilterQueryProvider class has to be defined to
allow the class to filter what is displayed on the screen.



        @Override

        protected void onCreate(Bundle icicle) {

                super.onCreate(icicle);

                m_adapter = new SimpleCursorAdapter(this,

                                android.R.layout.simple_list_item_1,

                                m_cursor,

                                PROJECTION,

                                new int[] { android.R.id.text1 },

                                CONTENT_URI,

                                DEFAULT_SORT_ORDER);



                m_adapter.setFilterQueryProvider(new

                          SimpleCursorAdapater.FilterQueryProvider()

                {

                     @Override

                     protected Cursor runQuery(CharSequence constraint) {

                         StringBuilder buffer = null;

                         String[] args = null;

                         if (constraint != null) {

                             buffer = new StringBuilder();

                             buffer.append("UPPER(");

                             buffer.append(m_projection[0]);

                             buffer.append(") GLOB ?");

                             String filter =
constraint.toString().toUpperCase() + "*";

                             if (m_filterMode == FILTERMODE_CONTAINS) {

                                  filter = "*" + filter;

                             }

                             args = new String[] { filter };

                         }



                         return m_contentResolver.query(CONTENT_URI,

                                      PROJECTION,

                                      buffer == null ? null :
buffer.toString(),

                                      args,

                                      m_sortOrder);

                     }

                     m_box = (AutoCompleteTextView)

                                  findViewById(R.id.autocomplete);

                     m_box.setAdapter(m_adapter);



There are two problems:



1.       I’m using the v1.1 DSK, and the constructor for SimpleCursorAdapter
 is defined as follows:

SimpleCursorAdapter<http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html#SimpleCursorAdapter%28android.content.Context,%20int,%20android.database.Cursor,%20java.lang.String%5B%5D,%20int%5B%5D%29>
(Context<http://developer.android.com/reference/android/content/Context.html>context,

                  int layout,


Cursor<http://developer.android.com/reference/android/database/Cursor.html>c,

String[] <http://developer.android.com/reference/java/lang/String.html>from,

int[] to);

The parameters CONTENT_URI and DEFAULT_SORT_ORDER are not defined for this
constructor.



2.       Where is the CONTENT_URI obtained from? In my case, the
SQLiteDatabase that the cursor argument refers to, was filled by reading in
the contents of  a text file.



Many thanks,

Paul



2009/4/8 Paul Moore <polom...@gmail.com>

> Hello,
>
> I have an application that involves reading a text dictionary file with
> about 7000 entries, and allowing the user to choose one of these. My first
> approach was to allow the user to select one of these by using a
> AutoCompleteTextView together with ArrayAdapter<String>. This works, but is
> very slow (~10 seconds to update the word list each time the user enters a
> character to narrow down the choice).
>
> I was wondering how to rework it so that I could use a database using a
> SimpleCursorAdapter instead. In other words, to hope that a SQL database
> could provide a more efficient ordering and access for the elements.
> Is this the best way to do it? I've also seen several references to
> SQLiteDatabase, but don't know which one to use.
>
> I found this code fragmant consisting of an extended SimpleAdapter.
> http://sacoskun.blogspot.com/2008/08...leadapter.html<http://sacoskun.blogspot.com/2008/08/autocompletetextview-with-simpleadapter.html>
>
> Unfortunately, this is not a complete worked out example. Could someone
> forward me a more complete example? I've found lots of code fragments, but
> no code that shows how to initialise the SimpleCursorAdapter contents, or
> how it works together with the AutoCompleteTextView.
>
> Many thanks,
> Paul

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to