Android programmatically disable autocomplete/auto

2019-01-14 05:17发布

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?

11条回答
淡お忘
2楼-- · 2019-01-14 05:44

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.

查看更多
来,给爷笑一个
3楼-- · 2019-01-14 05:55

'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

查看更多
Animai°情兽
4楼-- · 2019-01-14 05:55

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

android:inputType="textFilter"
查看更多
相关推荐>>
5楼-- · 2019-01-14 06:08

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"

查看更多
聊天终结者
6楼-- · 2019-01-14 06:09

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).

查看更多
登录 后发表回答