也许是晚了,但我发现这个问题优雅的解决方案:
前
禁用过滤设置文本后启用它(而不是玩焦点或/和延迟)。在这种情况下,您应该使用自定义控件。
见下面的例子:
public class CustomCompliteTextView extends AutoCompleteTextView {
private boolean mIsSearchEnabled = true;
public CustomCompliteTextView(Context context) {
super(context);
}
public CustomCompliteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomCompliteTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setSearchEnabled(boolean isEnabled) {
mIsSearchEnabled = isEnabled;
}
@Override
protected void performFiltering(CharSequence text, int keyCode) {
if (mIsSearchEnabled) {
super.performFiltering(text, keyCode);
}
}
}
与用法:
text.setSearchEnabled(false);
text.setText("Text you want to set");
// optional, if you also want to set correct selection
text.setSelection(text.getText().length());
text.setSearchEnabled(true);
这对我有效;我不需要设置程序化延迟。 – squeeish 2015-09-04 02:46:11