If something does not make sense please let me know. I am aware my questions are not always precise.
I have a listview that I am trying to filter by name. I have an EditText field, which users type in to filter the listview. The toString in the DirectoryListing class is overridden, allowing for correct comparisons.
Here is the problem: Say I have the following, each in their own row in the listview: "AC, BC, CD, AE". Now in the edit text field, if B is entered, the listview displays, "AC". A will display AC, BC. As you can see it will show the amount of items that match what was entered, but it just displays the approriate amount from the top down, not the correct items. Any idea what I am doing wrong? Here is my code.
//imports and some variable declaration
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directory);
final Handler handler = new Handler() {
//fill the listview to start
}
};
listing = new ArrayList<DirectoryListing>();
this.adapter = new DirectoryAdapter(this, R.layout.dir_rows, listing);
setListAdapter(adapter);
ProgressDialog = ProgressDialog.show(DirectoryActivity.this, "Please wait...", "Retrieving data ...", true);
viewOrders = new Runnable() {
//execute filling the original listview
};
TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
}
};
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
Thread thread = new Thread(null, viewOrders, "Background");
thread.start();
}
//other code
}
精彩评论