Android programmatically disable autocomplete/autosuggest for EditText in emulator

后端 未结 12 517
鱼传尺愫
鱼传尺愫 2020-12-03 02:37

Targeting Android 2.2

I have read the answers to the following questions:

Turn off autosuggest for EditText?

Android: Multiline & No autosuggest

相关标签:
12条回答
  • 2020-12-03 02:51

    You could simply use the EditText's setThreshold() method. Set the threshold to let's say 100 when you don't want to show predictions. If you want to re-activate showing predictions, set it back to a small int like 1 or 2 depending on your needs.

    0 讨论(0)
  • 2020-12-03 02:51

    The answer acceted as correct is faulty. To disable auto suggest add following property to your EditText XML

    android:inputType="textFilter"
    
    0 讨论(0)
  • 2020-12-03 02:58

    You can use the class AutoCompleteTextView and set the adapter that contains nothing AutoCompleteTextView Class Reference

    example

     public class CountriesActivity extends Activity {
       protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);
    
         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
       }
    
       private static final String[] COUNTRIES = new String[] {""};
     }
    
    0 讨论(0)
  • 2020-12-03 03:00

    I've tried all the above and none of above really helped me. I've search through available InputTypes and I've came up with a solution, which happened to be TYPE_TEXT_FLAG_AUTO_COMPLETE:

    mEditText.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);

    From its description:

    This generally means that the input method should not be showing candidates itself, but can expect for the editor to supply its own completions/candidates from InputMethodSession.displayCompletions().

    I haven't specified any completions set and as a result I'm not getting any auto-suggestions.

    PS. Flag InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD mentioned in commend above does this trick as well, but it also disables toggling the language in the keyboard.

    0 讨论(0)
  • 2020-12-03 03:08

    I was fighting with the same problem in the emulator. While testing, I realized that what was appearing wasn't the normal autocomplete, but a special Asian character preview (presumably because it requires multiple keys to generate one Asian character). So I solved this by setting the language to English. I think what I was seeing was the "Key Preview" option listed under the "Japanese IME" setting in "Language & keyboard".

    I'm guessing that it would be pretty hard to disable this within an individual App without delving into the keyboard handling and language support.

    0 讨论(0)
  • 2020-12-03 03:10

    You can also use following for disabling auto suggestion on any edittext.

    <EditText>
    android:inputType="textNoSuggestions|textVisiblePassword"
    </EditText>
    

    This worked for me.

    0 讨论(0)
提交回复
热议问题