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 up the drop-down. If I do not request focus, it would be better, but just better, not entirely all right. I tried dissmissDropDwon(), it doesn't help. So, Is there any way to stop the drop-down from showing up after setting text and focus to it?
actv.setText("Tim Hortons");
actv.setSelection(0, actv.getText().length());
actv.requestFocus();
actv.dismissDropDown(); // doesn't help
Thank you!
An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
Another solution is to clear the focus before setting the text:
mContactTxt.setFocusable(false);
mContactTxt.setFocusableInTouchMode(false);
mContactTxt.setText("");
mContactTxt.setFocusable(true);
mContactTxt.setFocusableInTouchMode(true);
You can try these steps:
When setting the text, also set the Threshold value to a large value so that the dropdown doesnot come.
actv.setThreshold(1000);
Then override the OnTouch to set the threshold back to 1.
actv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
actv.setThreshold(1);
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With