Sorry for my sluggishness but I can't figure out how to write a
runable Filter.

This is my theory:

- The ArrayAdapter get the Filter through the getFilter() function
- It triggers the function Filter.filter() to put the work into queue
- When it's excuted, it call Filter.performFiltering() function to get
the results
- The results then is passed to the publishResults() function to
update the ArrayAdapter

And things I can't figureout are:

- If I don't know the mechanism behind the ArrayAdapter and how to
change its filtering behavior. Changing the Filter class is simply not
enough because I don't know how to change the data that will be shown.
If only I know the array or list that the ArrayAdapter uses to store
its filtered data that will be pass to the AutoCompleteTextView, I can
just change it in the publisResults() function.

- One thing I can think about is changing the data that will be passed
from the ArrayAdapter to the AutoCompleteTextView but it seems like if
I want to do that I have to override alot of functions of the Adapter
class and that is not a easy task at all.

I tried this class
--------------
public class MyFilter extends Filter {

                @Override
                protected FilterResults performFiltering(CharSequence contrain) 
{
                        // TODO Auto-generated method stub
                        FilterResults fr = new FilterResults();
                        fr.count = 2;
                        String[] a = new String[]{"abc","def"};
                        fr.values = a;

                        return fr;
                }

                @Override
                protected void publishResults(CharSequence arg0, FilterResults
results) {
                        // TODO Auto-generated method stub
                        Log.i("Filter",results.count+"");
                if (results.count > 0) {
                    notifyDataSetChanged();
                } else {
                    notifyDataSetInvalidated();
                }
                }

        }
-------------

And it seems that my theory is somewhat right because I always log the
number that I set in the performFiltering function. But for this
Filter, all my data is shown in the AutoComplete drop down box.


On Apr 3, 10:20 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> >  - Where is the data that it need to work with? I can only see
> >  constrain in the performFilter() function
>
> The data is the data you pass to the ArrayAdapter. Or the ArrayAdapter's data.
>
> >  - For the publishResults() function. What do I need to do with it? I
> >  don't see anything like a context that can help me reach out of the
> >  class so how can I publish the result?
>
> Just use the notify methods of the Adapter. For instance:
>
>         @Override
>         protected void publishResults(CharSequence constraint,
>                 FilterResults results) {
>             //noinspection unchecked
>             mObjects = (List<T>) results.values;
>             if (results.count > 0) {
>                 notifyDataSetChanged();
>             } else {
>                 notifyDataSetInvalidated();
>             }
>         }
>
> >  - And for the FilterResults class, isn't the values need to be
> >  Object[] or List<Object> because it's said to "Contains all the values
> >  computed by the filtering operation. ".
>
> No, it has to be an Object. For instance, the CursorAdapter publishes
> a Cursor as the result, not an array or a list.
>
>
>
>
>
> >  Thank you.
>
> >  On Apr 3, 1:36 am, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> >  > Hi,
>
> >  > The best thing to do is indeed to override getFilter() and return a
> >  > Filter that will do what you are proposing. The current ArrayAdapter's
> >  > Filter simply matches the text against the first characters of each
> >  > entry of the array.
>
> >  > On Wed, Apr 2, 2008 at 10:31 PM, AkaZn <[EMAIL PROTECTED]> wrote:
>
> >  > >  Hi
>
> >  > >  I want to somehow emulate the idea T9 Text Input  (not it but similar
> >  > >  to it) and I want to use the AutoCompleteTextView to suggest the user
> >  > >  the word they can choose. But only overriding the performFiltering
> >  > >  function of the AutoCompleteTextView class is not enough to do the
> >  > >  work as use my customize function to do the filter process or at least
> >  > >  use regex.
>
> >  > >  So how can I customize the filtering process so that I can customize
> >  > >  the dropdown list of the AutoCompleteTextView?
>
> >  > >  I noticed that in the ArrayAdapter class, there is a getFilter()
> >  > >  function but I don't know if I can do anything with it.
>
> >  > >  Thank you very much.
>
> >  > >  ---------------
> >  > >  For those who are not familiar with the T9:
> >  > >  http://www.t9.com/
>
> >  > --
> >  > Romain Guywww.curious-creature.org
>
> --
> Romain Guywww.curious-creature.org
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to