I use the following code to set text to an AutoCompleteTextView field. But I noticed that when I set certain text (not all text, but some) to it, it will automatically pop u
You can also enable/disable the drop-down like so:
// disable
actv.setDropDownHeight(0);
// enable
actv.setDropDownHeight(LayoutParams.WRAP_CONTENT);
You can try
searchInput.setAdapter((ArrayAdapter<String>) null);
searchInput.setText(text);
searchInput.setAdapter(adapter);
Source
Maybe it is to late, but I've found elegant solution for this problem:
Disable filtering before setting text and enabling it after (instead of playing with focus or/and delays). You should use custom control in this case.
See example below:
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);
}
}
}
And usage:
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);
I need to add some delay to make this thing work.
This worked for me:
new Handler().postDelayed(new Runnable() {
public void run() {
if(carModel.isPopupShowing())
carModel.dismissDropDown();
}}, 500);
I too faced a scenario and I resolved in this way.
dismissDropDown()
for that autocompleteTextView.Please find the below snippet
if(null != testText && testText.length() != 0) {
mAutoCompleteSearch.setText(incomingActivity.toString());
mAutoCompleteSearch.dismissDropDown(); //Dismiss the drop down
} else {
mAutoCompleteSearchDocketActivity.setText("");
// Here it(drop down) will be shown automatically
}
Hope, this would help for someone, Cheers !