views:

109

answers:

2

Hi, I have been implementing a class which class extends ArrayAdapter and implements Filterable. The filtering part (in the performFiltering method()) seems to go ok, it fills the FilterResults object just as expected. But then I think I'm not doing it right on how to publish the results, atm I have :

protected void publishResults(CharSequence prefix, FilterResults results) 
  {
    // NOTE: this function is *always* called from the UI thread.
     subItems =  (Vector)results.values;
     notifyDataSetChanged();

  }

But this simply won't "populate" my List with the received data. So now my question is how do I populate my List with the received results ? Do I have to do that programmatically ?

+1  A: 

I had had the same problem. Try to be more aggresive:

protected void publishResults(CharSequence prefix, FilterResults results) 
  {
    // NOTE: this function is *always* called from the UI thread.
     subItems.clear();
     subItems.addAll((Vector<T>)results.values);
     notifyDataSetChanged();

  }

Obviously I assume that your "results" object contains the right data

This approach has solved my problem

Francesco
one more question : it actually simply replaces the exisiting List-elements with the results elements right ? So I don't have to redo all the getView() method stuff right ? Cause I am not using simple standard elements for my List !
TiGer
A: 

Actually I got it working with the next piece of code :

subItems =  (Vector<serverContentElement>)results.values;

notifyDataSetChanged();
clear();
for(int i = 0; i < subItems.size(); i++)
   add(subItems.get(i));

For me this has been the only way to get it working... Just a shame there aren't very concise examples on the net...

TiGer