Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4249448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:23:55+00:00 2026-05-21T04:23:55+00:00

I use the following code to set text to an AutoCompleteTextView field. But I

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:23:55+00:00Added an answer on May 21, 2026 at 4:23 am

    To answer my own question in case someone had the same problem:

    One characteristics of AutoCompleteTextView is that if you change its text programmatically, it will drop down the selection list if the following two conditions are met: 1. It has focus; 2. The list is longer than 30-something items.

    This behavior is actually, IMHO, a design flaw. When the program sets text to an AutoCompleteTextView, it would mean that the text is already correct, there is no point to popup the filtered list for user to further choose from.

    actv.setText("Tim Hortons"); 
    actv.setSelection(0, actv.getText().length()); 
    actv.requestFocus(); 
    actv.dismissDropDown();    // doesn't help 
    

    In the above code, requestFocus() forces the ACTV to get the focus, and this causes the drop-down to pop up. I tried not to reqeuest focus, instead, I called clearFocus() after setting text. But the behavior is very …. unnatural. dissmissDropdown() doesn’t help because …. I don’t know, it just doesn’t help. So, after much strugle, I came up with this work-around:

    1. When initializing the widget, I remembered the adapter in a class field.
    2. Change the above code to:

      mAdapter = (ArrayAdapter<String>)actv.getAdapter(); // mAdapter is a class field        
      actv.setText("Tim Hortons"); 
      actv.setSelection(0, actv.getText().length()); 
      actv.setAdapter((ArrayAdapter<String>)null); // turn off the adapter
      actv.requestFocus();
      Handler handler = new Handler() {
      public void handleMessage(Message msg) {
          ((AutoCompleteTextView)msg.obj).setAdapter(mAdapter);
          };
      Message msg = mHandler.obtainMessage();
      msg.obj = actv;
      handler.sendMessageDelayed(msg, 200);   // turn it back on after 200ms
      

    Here the trick is set the ACTV’s adapter to null. Because there is no adapter, of course the system will not pop up the drop-down. But the message will reset the adapter back to the ACTV after the programmed delay of 200ms, and the ACTV will work normally as usual.

    This works for me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following code: Calendar calendar = new GregorianCalendar(0,0,0); calendar.set(Calendar.YEAR, 1942); calendar.set(Calendar.MONTH, 3);
I can use the following code for tiny little queries: DECLARE @sql VARCHAR(8000) SET
I have the following code that I am playing with: <script type=text/javascript> var Dash
I have the following code that I'm trying to use to populate a ComboBox,
I use following code: Create a retry policy, when error, retry after 1 second,
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
I use the following code try to create an array of string vectors, I
I use the following code to layout network drives on a system. I want
I use the following code to allocate a Console for a WinForm application. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.