Q:

ListView and Adapter filter not updating

I am setting up an adapter with a corresponding ListView. When I filter the adapter and the ListView, I output their count and it is still the same. However, on the application, it seems like the listView has been filtered as it only displayed the items that match the filter input (in this case "Berlin").
    String string_list[] = {"Paris", "London", "Milano", "Madrid", "Berlin", "Moscow", "Washington" };

    // Set up ListView and Adapter
    myAdapt = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,string_list);
    myListView.setAdapter(myAdapt);
    myListView.setItemsCanFocus(false);
    myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View itemView, int position,
                long arg3) {
            // One of my methods
            manageFavorites(arg0, itemView, position, arg3, myListView);
        }
    });
    // Debug
    myAdapt.getFilter().filter("B");
    tv1.setText("myAdapt.getCount() =" + myAdapt.getCount());

    myListView.setTextFilterEnabled(true);
    myListView.setFilterText("B");
    tv2.setText("myListView.getCount() =" + myListView.getCount());

Is there a way that when calling a filter on an adapter or listView, the variables change according to the filer? In this case, I filter myAdapt and myListView with the character B, so I would like to have myAdapt and myListView carry the only item that matchs that character, which is Berlin.
Note that my class extends Activity. Please point out if I should be using ListActivity or CustomAdapter as I have seen around SOF. 

A:

You have to add a listener on your filter that will be triggered when the filtering completes.
myAdapt.getFilter().filter("B", new Filter.FilterListener() {
    public void onFilterComplete(int count) {
        tv2.setText("myListView.getCount() =" + count);    
    }
}

See Filter class in Android Reference for details.

