When I use the autocompletetextview everything works fine except it keeps switching between two positions: the correct one right below the textview and quite a ways lower. It starts wrong, but almost immediately moves to the correct position. However this is very annoying when typing or backspacing as it happens for every letter. I am using android studio.
It appears as if two events are simultaneously trying to decide the layout. Sometimes it will stick in one position or the other.
**I slowed down the filtering process with a custom adapter and it looks like when text is entered it moves into the incorrect position, and then when the filtering is done it moves back into the correct position.
Incorrect
Correct:
java (in OnCreate())-
String[] drugs = new String[]{"Nexium","Amoxicillin","LEVOCETIRIZINE DIHYDROCHLORIDE", "Advil", "Advair Diskus", "Daraprim"};
AutoCompleteTextView drugNameAutoComplete = ((AutoCompleteTextView) findViewById(R.id.drugNameEditText));
drugNameAutoComplete.setAnimation(null);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,drugs);
drugNameAutoComplete.setAdapter(adapter);
And the layout code-
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/drugNameEditText"
android:enabled="true"
android:singleLine="true"
android:layout_below="@+id/lookingForView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:dropDownVerticalOffset="50dp"
android:hint="@string/drug_name" />
If I remove the dropDownVeticalOffset I get flickering between the correct value and this-
To change this position use dropDownAnchor attribute and reference another view id. (view under autocomplete)
android:dropDownAnchor
View to anchor the auto-complete dropdown to. If not specified, the text view itself is used.
and you have many attributes for dropdown..
You better to use implement Filter to autocomplete adapter and pass the entered text from OnQueryTextListener of autocomplete, and set the selected text by calling adapter.getitem.
Change your xml to-
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/drugNameEditText"
android:enabled="true"
android:singleLine="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
**android:dropDownVerticalOffset="0dp"**
**android:dropDownAnchor="@id/drugNameEditText"**
android:hint="drug" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With