我找不到更合适的解决方案则是:
我加入这个焦点变化监听
actName.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
ArrayList<String> results =
((UsersAutoCompleteAdapter) actName.getAdapter()).getAllItems();
if (results.size() == 0 ||
results.indexOf(actName.getText().toString()) == -1) {
actName.setError("Invalid username.");
};
}
}
});
凡getAllItems()
返回ArrayList
包含建议的方法。
所以,当我输入一些用户名,然后移动到另一场这个监听器被触发,它会检查建议列表不为空,如果输入的用户名是在该列表中。如果条件不满足,则显示错误。
而且我有OK
按一下按钮相同的检查:
private boolean checkErrors() {
ArrayList<String> usernameResults =
((UsersAutoCompleteAdapter) actName.getAdapter()).getAllItems();
if (actName.getText().toString().isEmpty()) {
actName.setError("Please enter a username.");
return true;
} else if (usernameResults.size() == 0 || usernameResults.indexOf(actName.getText().toString()) == -1) {
actName.setError("Invalid username.");
return true;
}
return false;
}
因此,如果AutoComplete
观点仍然集中,错误再次检查完成。
使用微调,而不是... – Selvin
@Selvin因为有用户名的很多,而且客户希望有自动完成的TextView我不能使用微调。感谢您的建议 – nikmin
如何使用搜索选项列表视图? –