title: Android filter and sort ListView with adapter set during Async task
body: <p>I'm making a ListView with data I get from a database placed in a server. The ListView has TWO TextViews for each row, one for the cities, and the other one for the ID's each city has on the database, but this textview(the ID's one) is HIDDEN from the ListView, so the user can only see cities.</p>
  
  <p>Everything works fine, but now I want to add a search bar to the listview so I can filter the cities, but i'm getting the following problems:</p>
  
  <p>1.-The adapter of the ListView is a Simple Adapter, as you can see on the code, and I have found no examples of how to filter a Listview using such an adapter.</p>
  
  <p>2.-I'm getting the info for the ListView through an Async Task, and setting up the ListView inside the <em>onPostExecute</em> method of the Async Task, and again, I have found no examples of filtering it when its in such a place.</p>
  
  <p>Here is the "relevant" code. If somebody needs the complete code, just ask me for it.</p>
  
  <pre><code>public class SQLWebVer extends ListActivity implements OnItemClickListener{
  ProgressDialog barraProgreso;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; listaCiudades;
      .
      .//some more varibles for the class
      .
      protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.sqlwebver);
  
      // Hashmap de la ListView
      listaCiudades = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      new cargaCiudades().execute();//this is the call to the async task
  
      }
      class cargaCiudades extends AsyncTask&lt;String, String, String&gt;{//the async task
      .
      .//here are the onPreExecute and doInBackground methods
      .
           protected void onPostExecute(String file_url) {
          barraProgreso.dismiss();//quita la barra de la pantalla
          runOnUiThread(new Runnable(){//actualiza la UI(la listView)
  
              public void run() {
                  // TODO Auto-generated method stub
                  ListAdapter adapter = new SimpleAdapter 
                                        (SQLWebVer.this, listaCiudades, 
                                        R.layout.sqlweblist_item,
                            new String[]{"key_id", "key_ciudad"},new int[]
                                        {R.id.ID_CIUDAD, R.id.CIUDAD});
  
                  setListAdapter(adapter);
              }
  
          });
          }
       }
  </code></pre>
  
  <p>I have tried to add the filter feature both on the onCreate and onPostExecute method, but with no luck so, any suggestions?</p>
  
  <p>P.D:BONUS question, how could I sort my ListView alphabetically by cities but keeping each ID related to his city?(without changing the php files)</p>
  
  <p>EDIT: I solved the problem by creating a Custom Base Adapter which implements filterable. Wasn´t as hard as I thought at first ;)</p>