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 Arra
I thought I would share my modified version of Sam's excellent answer. I just made 2 minor changes to support multi-line text in both the filter string and the text being filtered:
final String valueText = value.toString().toLowerCase().replace('\r', ' ').replace('\n', ' ');
// First match against the whole, non-splitted value
if (valueText.startsWith(prefixString)) {
newValues.add(value);
} else {
// Break the prefix into "words"
final String[] prefixes = prefixString.split("\\s+");
final int prefixCount = prefixes.length;
int loc;
// Find the first "word" in prefix
if(valueText.startsWith(prefixes[0]) || (loc = valueText.indexOf(' ' + prefixes[0])) > -1)
loc = valueText.indexOf(prefixes[0]);
// Find the following "words" in order
for (int j = 1; j < prefixCount && loc > -1; j++)
loc = valueText.indexOf(' ' + prefixes[j], loc + 2);
// If every "word" is in this row, add it to the results
if(loc > -1)
newValues.add(value);
}
I just replace \r and \n with spaces. You could also remove other white-space if needed, such as \t, or change to a regular expression... for me \r and \n was enough. I also changed the split() to \s+ so that it splits on any white-space.