Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable AutoCompleteTextView's drop-down from showing up?

Tags:

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!

like image 720
wwyt Avatar asked Mar 31 '11 04:03

wwyt


People also ask

What is Auto complete text view in Android?

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.


2 Answers

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);
like image 150
Itay Kahana Avatar answered Nov 01 '22 10:11

Itay Kahana


You can try these steps:

  1. When setting the text, also set the Threshold value to a large value so that the dropdown doesnot come.

     actv.setThreshold(1000);
    
  2. 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;
        }
    });
    
like image 26
user520510 Avatar answered Nov 01 '22 08:11

user520510