【发布时间】:2016-05-02 09:42:23
【问题描述】:
建议存储在ArrayList<String>. getSuggestions() 方法返回String 的正确列表,关键是我将特殊字符替换为随意字符。 IE。当我输入xeres 时,我希望得到与输入xérès 相同的结果,但问题是当我输入xérès 时,dropdown 出现,而当我输入xeres,它没有,即使建议变量具有相同的值...
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 2) {
suggestions = getSuggestions(s.toString());
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.dropdown_textview_row, suggestions);
autoTxtSearchPointer.setAdapter(adapter);
}
}
感谢您的帮助! :)
编辑:更精确的代码
autoTxtSearchPointer = new AutoCompleteTextViewCustom(this);
autoTxtSearchPointer.setHint(R.string.search);
autoTxtSearchPointer.setSingleLine();
autoTxtSearchPointer.setImeOptions(EditorInfo.IME_ACTION_DONE);
autoTxtSearchPointer.setLayoutParams(editParams);
autoTxtSearchPointer.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
autoTxtSearchPointer.setThreshold(2);
autoTxtSearchPointer.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 2) {
suggestions = getSuggestions(s.toString());
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.dropdown_textview_row, suggestions);
autoTxtSearchPointer.setAdapter(adapter);
}
}
@Override
public void afterTextChanged(Editable s) {}
});
}
编辑 2:是因为我使用了 Normalizer 吗?
private String normalize(String str) {
return Normalizer
.normalize(str, Normalizer.Form.NFKD)
.replaceAll("[^\\p{ASCII}]", "");
}
【问题讨论】:
标签: android android-arrayadapter autocompletetextview textwatcher unicode-normalization