I have recently added a bounty to this SO question, but realise the original question asks for a SimpleAdapter and not an ArrayAdapter. So, this question relates to the ArrayAdapter:
I would like to be able to filter an ArrayAdapter in a ListView using multiple search terms. For example, if my list contains the following items:
a thing
another thing
a different thing
nothing
some thing
If I search for 'thing' then all the terms should be returned in the filter results. This is normal behaviour that can be accomplished using the following code:
private TextWatcher filterTextWatcher = new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
myAdapter.getFilter().filter(s.toString());
}
};
However; if I enter the search phrase 'a thing
', I expect the following results to be shown:
a thing
another thing
a different thing
In fact, all I get returned in the result 'a thing
'. Since the filter is looking for the entire string, it treats the space as a part of the search term. Essentially, what I'm asking is how do I filter the list not by one specific string, but by multiple search terms, each separated by spaces? So long as each of the search terms appear at least once in the item, then that item should be returned in the result.
Similar questions seem to have been asked before on SO (for example, see the link at the top of this post, which concerns SimpleAdapters), but nowhere have I found an actual way to accomplish this. I suppose the answer would involve separating the search phrase into individual strings, delimited by the space character, and then running the search multiple times on each string, and only returning the results which match for all of the iterations...