0

Im using a Filter for an ArrayAdapter. Now I would like to have following Feature:

For Example my Listview contains the word käuflich and the search Input is kauf, käuflich should be displayed as result. So ö,ä,ü should be replaced additionally by o,a,u. Is this possible?

This is my simple filter

    public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
        // When user changed the Text
        Activity.this.adapter.getFilter().filter(cs);  
    }

Thanks

Oli
  • 3,496
  • 23
  • 32

1 Answers1

1

You can use the java.text.Normalizer to remove the accents. When iterating over list items in Filter.performFiltering(CharSequence), do the following:

for(int i = 0; i<Original_Names.size(); i++){
    filterableString = Original_Names.get(i);

    String s = Normalizer.normalize(filterableString, Form.NFD);

    // Remove Accents
    String withoutAccents = 
        s.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");

    if(withoutAccents.toLowerCase().contains(filterString)){
        Filtered_Names.add(filterableString);
    }
}

A word of caution here: Link

Community
  • 1
  • 1
Vikram
  • 51,313
  • 11
  • 93
  • 122
  • Thank you, code is implemented but the search is very slow. My Array list is filled from a SQL query, may this is the Problem? – Oli Sep 20 '13 at 09:24
  • @Oli Yes, that can be the problem. But sorry, I cannot give you a sure answer. Is the list getting filtered correctly? – Vikram Sep 26 '13 at 20:29