Android programmatically disable autocomplete/autosuggest for EditText in emulator - android

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?

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.

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

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.

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

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[] {""};
}

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

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.

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.

You can also use following for disabling auto suggestion on any edittext.
<EditText>
android:inputType="textNoSuggestions|textVisiblePassword"
</EditText>
This worked for me.

Try This
android:importantForAutofill="no"

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.

'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

The answer acceted as correct is faulty. To disable auto suggest add following property to your EditText XML
android:inputType="textFilter"

Related

How to disable EditText auto suggestion when only TESTING by Espresso in Android

What I want
when real, use auto suggestion
when testing, do not use auto suggestion because the suggestion view make testing trouble I think.
I just want to know the way using typeText()
when use replaceText(), it' ok.
For testing,I used to set inputType like this, but It doesn't work.
const val emailInputType =
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
editText.inputType = emailInputType
I guess, there is a way to set build.gradle(.app)
Is there a way to do My job(hide edittext auto suggestion when focusing in testing) in a build.gradle(.app) setting?
android{
testOptions{
something...
}
}
or is there another way?

Enable Edittext after disabling it

OnButtonClick listener I want to disable the EditText to edit, and then turn it on again.
With below two lines I disabled EditText
editTextWight.setEnabled(false);
editTextWight.setFocusable(false);
But when I try to turn it back fails. The keyboard does not open.
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
editTextWight.setClickable(true);
editTextWight.setEnabled(true);
Please help me to enable the EditText.
You can try this two lines that work for my project code:
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
I do this for example afterTextChanged() is called because I had to disable this EditText first then enable it later!
So, just try it with ONLY two method calls above instead of all the four.
Good luck and let me know if it worked!
Thank you Eenvincible and sajan. Your answers togheter help me to solve my problem. I enabled the editing window with these 4 methods.
editTextWight.setEnabled(true);
editTextWight.setInputType(InputType.TYPE_CLASS_NUMBER);
editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
to disable edit text use
editTextWight.setEnabled(false);
editTextWight.setInputType(InputType.TYPE_NULL);
editTextWight.setFocusable(false);
to enable edit text use
editTextWight.setEnabled(true);
editTextWight.setInputType(InputType.TYPE_CLASS_TEXT);
editTextWight.setFocusable(true);

How to check whether android EditText keyboard Auto Suggestion is enabled or not?

In my project I am working on EditText.I have set an input type for this EditText using below code.
mEdit.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
| InputType.TYPE_TEXT_FLAG_MULTI_LINE);
If we disabled the Auto Suggestion using keyboard settings, How to know Autosuggestion is enabled or disabled While editing. I need to know this in onTextChanged listener.
You can check like this
if(mEdit.getInputType() == InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS){
}
But never tried.

Three Questions

First, I want set unchecked all the 8 checkboxes using a loop like this:
for (int i=1;i<8;++i){
CheckBox view1 = (CheckBox) findViewById(R.id.CheckBox0+String.valueOf(i));
view1.setChecked(false);
}
It Doesn't work, but you get the idea what I mean. How can solve it?
Second: With Eclipse I set a form list. What is making that when application starts, it immediately shows the keyboard and is focused in a editing field?. I want that the keyboard appears only after the user touches an editing field.
Third: How I set the properties of the editing field that when user touches enter, the focus doesn't pass to the next editing field. Thanks in advance.
Firstly, asking multiple questions together isn't good; it prevents people from answering when they know only one of the solutions.
1 - Relying on the IDs CheckBox0, CheckBox1, CheckBox2, ... to be in order is very risky and is bad practice. In this case, you should be using getIdentifier; this will fetch IDs CheckBox1, then CheckBox2, etc. reliably.
for (int i=1;i<8;++i){
CheckBox view1 = (CheckBox) findViewById(getResources().getIdentifier("CheckBox" + i, "id", getPackageName()));
view1.setChecked(false);
}
2 - You need to use a stateHidden modifier for this:
<activity
android:name="com.example.NoKeyboardActivity"
android:windowSoftInputMode="stateHidden" />
3 - Use imeOptions for this; actionNone is the one you're looking for, or (as per comments), actionDone to enable the "Done" button.
<TextView
...
android:imeOptions="actionNone" />
For the resources to have fixed ids after each build, you will have to declare the resources in public.xml, then you can access the ids sequentially. Check here
Also R.id.CheckBox0 is an int so do
findViewById(R.id.CheckBox0+ i)
after you have declared all checkboxes in public.xml
For the second question in the activity manifest add
android:windowSoftInputMode="stateHidden"
Third:
I think you will have to reference the same edittext in layout for android:nextFocusDown.
Not sure if this will work give it a try
1 - Remember that this is Java not Javascript, you can't do this (R.id.CheckBox0+String.valueOf(i)). Normally I create an array of int with all the R.id inside and loop through them.
2 - You could use also android:windowSoftInputMode="stateUnchanged" to not hide the keyboard if it's already showing.
3 - That's the way it's supposed to be, but you can use on the edittext the property android:imeOptions="actionNone", so the enter button will do nothing.

Android: How to enable my button back if EditText is not empty?

I have 2 EditTexts; 01 and 02. My button will be disabled once the activity is started and when these two EditText contain text, the button has to be enabled again. However my button is always disabled and can't enable it using button.setEnabled(true);.
Can anyone help me with this?
summit.setEnabled(false);
buttonEnable();
public void buttonEnable(){
if (feedback.length()>0 && email.length()>0){
summit.setEnabled(true);
}else{
summit.setEnabled(false);
}
}
You're correct about needing a TextWatcher. The afterTextChanged(Editable) method is the one you're interested in for something like this. Call your buttonEnable() method from it, and add the TextWatcher to any applicable text fields. (Looks like feedback and email from your sample.)
One easy way can also be to set onKeyListener to your editText(), then if there is something in editText(), set button enable if nothing disable it.

Categories

Resources