Is there a way to programmatically turn off that autosuggest list which pops up as you type in EditText?
Is there a way to programmatically turn off that autosuggest list which pops up as you type in EditText?
I had the same question but I still wanted to set this option in my XML file so I did a little more research until I found it out myself.
Add this line into your EditText.
android:inputType="textFilter"
Here is a Tip. Use this line if you want to be able to use the "enter" key.
android:inputType="textFilter|textMultiLine"
You can solve this problem by using this:
android:importantForAutofill="no"
Android O has the feature to support Auto-filling for fields,Just only use this in your xml, It will disable autofill hints
For the android version 8.0 or above this code is not working and for the autocomplete textview also this code not working so i will suggest you to use below code for the Disable the auto suggestions in 8.0 or above android vesrion use this property of edittext android:importantForAutofill="no"
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:focusable="false"
android:imeOptions="actionDone"
android:maxLength="80"
android:maxLines="1"
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorBlack"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp"
app:bFontsEdt="light" />
and for the AutoComplete textview like this use this Field to Disable Auto suggestion android:importantForAutofill="no" :
<AutoCompleteTextView
android:id="@+id/autocompleteEditTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_3sdp"
android:layout_marginTop="@dimen/_5sdp"
android:background="@null"
android:imeOptions="actionDone"
android:singleLine="true"
android:text=""
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorGrayDark"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp" />
This worked for me
android:importantForAutofill="no"
android:inputType="none|textNoSuggestions"
OK, the problem was - in Eclipse you don't get suggestion for flag named: textNoSuggestion
And you can't set it in main.xml (where you design UI) because that attribute for inputType isn't recognized. So you can set it in code using int const:
EditText txtTypeIt = (EditText) this.findViewById(R.id.txtTypeIt);
txtTypeIt.setInputType(524288);
And thanks jasta00 for helping me out figure answer for this one.
// 100% correct & tested
txtKey = (EditText) view.findViewById(R.id.txtKey);
txtKey.setPrivateImeOptions("nm");
txtKey.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
txtKey.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
}
if you don't want suggestion you can use "none"
android:inputType="none|numberDecimal"
Find a good solution for auto suggestions with TextWatcher. The suggestions will appear for user, but user will not be able accept them.
/*...*/
editText.addTextChangedListener(textWatcher);
/*...*/
}
private final TextWatcher textWatcher = new TextWatcher() {
long timestamp = 0L;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!longClickable && count - before > 1 && timestamp < System.currentTimeMillis()) { // disable suggestions click
String str = s.toString();
str = str.substring(0, before);
timestamp = System.currentTimeMillis() + 20;
inputText.setText(str);
inputText.setSelection(inputText.getText().length());
}
}
@Override
public void afterTextChanged(Editable s) {
}
};
Also this works good when you don't need a long click with copy/paste functionality