Diacritics/international characters in AutoCompleteTextView

前端 未结 8 1927
耶瑟儿~
耶瑟儿~ 2021-02-15 17:02

I have a (array) list

Car
Something
Šibica
Čavao
Cavao

Is there a way to \"force\" AutoCompleteTextView so if user type in letter \"c\"

8条回答
  •  长发绾君心
    2021-02-15 17:08

    @svenkapudija 's excellent answer can be generalized to most Latin script languages using java.text.Normalizer. In the filter code, replace:

                        String valueTextNoPalatals = toNoPalatals(valueText);
                        String prefixStringNoPalatals = toNoPalatals(prefixString);
    

    with:

                    String valueTextNoPalatals = Normalizer
                            .normalize(valueText, Normalizer.Form.NFD)
                            .replaceAll("[^\\p{ASCII}]", "")
                            .toLowerCase();
    
                    String prefixStringNoPalatals = Normalizer
                            .normalize(prefixString, Normalizer.Form.NFD)
                            .replaceAll("[^\\p{ASCII}]", "")
                            .toLowerCase();
    

提交回复
热议问题