Android programmatically disable autocomplete/autosuggest for EditText in emulator
Asked Answered
N

13

50

Targeting Android 2.2

I have read the answers to the following questions:

Turn off autosuggest for EditText?

Android: Multiline & No autosuggest in EditText

I have tried the following variations on the suggestions:

setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER);

setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL | InputType.TYPE_TEXT_VARIATION_FILTER);

setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL | InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

All of these work on most devices I've been testing (Droid X, Droid 2, Thunderbolt, Incredible) but don't work on the emulator and at least 1 device (Samsung GT i5500).

Is there any other way to programmatically disable the autocomplete/autosuggest for an EditText in a way the emulator and certain devices will recognize and respect?

Naylor answered 8/6, 2011 at 15:42 Comment(3)
Please bear in mind that all of these are simply hints to the input method editor. There is no requirement for any input method editor to honor them. Hence, it is all but guaranteed that there will be some pieces of hardware, or some third-party IMEs, that fail to honor the request. Now, I would expect that the emulator would honor them, since it has the standard input method editor, but I have not tried suppressing suggestions, either.Cryohydrate
@Naylor were you finally able to find a solution that works on the emulator and on all devices?Breakout
@Breakout Adding android:inputType="textVisiblePassword" seemed to work for all of my use cases. Also, make sure you aren't using the Japanese IME in the emulator.Naylor
E
20

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.

Elissaelita answered 15/1, 2013 at 8:32 Comment(4)
This is the most appropriate solution, the others are hacks imoPringle
All the solutions are hacky, but I think this is the least hacky :)Lurk
What if I have mentioned some other inputType in xml of that EditText as well, like textEmailAddressDuluth
It works. Crazy. It even disables the Android-O Autofill UI. Thank you so muchOwl
T
49

For Vodafone 845 (2.1), huawei 8800 (2.2) devices, textVisiblePassword seems to prevent word prediction.

vendorId.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

or

android:inputType="textVisiblePassword"

[Edit] this answer is quite old and I don't have the environment anymore to test to get up-to-date info for comments here, sorry.

Tertian answered 5/9, 2011 at 22:1 Comment(3)
Be careful of this, on non-English keyboards this may disable some of the features such as toggling the language.Twinkling
You're showing how to do it in code vs doing it in the XML layout file. But you're giving different amount of flags. Which is the correct flag(s) to use?Haig
The above won't work for me. When I click on InputText it shows the suggestion. Then I tried android:importantForAutofill="no" It Works for meDiscordant
A
25

In the layout XML, add the following attribute to your EditText:

android:inputType="text|textNoSuggestions"

If neither this, nor the above approaches work, then this is almost certainly a problem with the emulator and the other device, and you should contact the manufacturers directly.

See also: android:inputType (note that EditText is a subclass of TextView, which is why this attribute also works for EditTexts).

Animadversion answered 16/8, 2011 at 17:24 Comment(2)
Phil, I think you meant the activity's xml file, not AndroidManifestPhotoperiod
This answer is incorrect, you have to add following property to your EditText XML android:inputType="textFilter"Ellery
E
20

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.

Elissaelita answered 15/1, 2013 at 8:32 Comment(4)
This is the most appropriate solution, the others are hacks imoPringle
All the solutions are hacky, but I think this is the least hacky :)Lurk
What if I have mentioned some other inputType in xml of that EditText as well, like textEmailAddressDuluth
It works. Crazy. It even disables the Android-O Autofill UI. Thank you so muchOwl
A
7

personally, this code help me:

autoCompleteTextView.setAdapter(null);
autoCompleteTextView.setText(address);
autoCompleteTextView.setAdapter(adapter);

I want to disable suggestions when I set text so I remove the adapter and after I call setText, I return it.

so if you want to disable suggestion just use:

autoCompleteTextView.setAdapter(null);
Aegaeon answered 23/10, 2014 at 8:58 Comment(0)
F
2

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[] {""};
 }
Furnace answered 13/12, 2012 at 11:37 Comment(0)
P
2

Using android:inputType="textNoSuggestions|textVisiblePassword" for Edittext fix the problem.

Pericline answered 18/3, 2015 at 7:59 Comment(0)
S
1

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.

Supersonics answered 21/8, 2011 at 19:11 Comment(0)
T
1

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.

Thirsty answered 19/2, 2013 at 17:9 Comment(1)
EditText does not have setThreshold() method.Munguia
P
1

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

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

This worked for me.

Pericline answered 2/7, 2014 at 9:51 Comment(0)
D
0

Try This android:importantForAutofill="no"

Discordant answered 26/1, 2020 at 19:9 Comment(0)
F
0

To turn off auto corrections/suggestions on EditText programmatically:

 editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

Note: the aforementioned works for SearchView etal.

Flu answered 26/7, 2022 at 9:45 Comment(0)
K
-2

'oninput' event in the input, ran the following function:

function RefreshAutoComplete(elm) {
elm.keyup();
elm.focus();
}

I run the auto complete manually, and it works

Thank you all for the help

Kroll answered 7/1, 2013 at 12:0 Comment(0)
E
-3

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

android:inputType="textFilter"
Ellery answered 16/2, 2012 at 20:8 Comment(1)
Please read my full question. I already tried android:inputType="textFilter".Naylor

© 2022 - 2025 — McMap. All rights reserved.