当AutocompleteTextView的建议列表中没有匹配项时,我希望得到一条消息。如果我使用addOnTextChangeListener,则会在用户键入字符时始终显示消息,但我只想在没有匹配项时才显示消息。请告诉我如何实现此功能,列表来自Web服务。谢谢。
searchEdit = (AutoCompleteTextView)findViewById(R.id.searchEdit);
searchEdit.setCursorVisible(false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, menuItems);
searchEdit.setAdapter(adapter);
searchEdit.addTextChangedListener(this);
@Override
public void afterTextChanged(Editable arg0) {
}
@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 (!searchEdit.isPerformingCompletion()) {
Toast.makeText(getApplicationContext(), "No Item Found", 2000).show();
return;
}
}