The layout is basic: an EditText at the top followed by a ListView. EditText has a TextWatcher.onTextChanged implemented so that ArrayAdapter.getFilter.filter is called with the entered text. ArrayAdapter's data is refreshed asynchronously on resume (see code snippet below). Easy enough, works just fine too... right up until the screen orientation is changed. Why would filtering suddenly break when the phone is turned sideways?
public class SometActivity extends ListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
...
listAdapter = new ArrayAdapter<MemoryStatistic>(this, R.layout.list_item);
setListAdapter(listAdapter);
searchText = (EditText)findViewById(R.id.searchText);
searchText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence text, int start, int before, int count)
{
listAdapter.getFilter().filter(text);
}
...
}
...
}
@Override
protected void onResume()
{
asyncRefreshListAdapter();//refresh the data asynchronously when activity is resumed
}
}