Even though I'm setting the setOnItemClickListener on the AutoCompleteTextView and performing some custom operations in it, once that method is done, the list dismisses and prints out the object.toString in the editbox.
I want to prevent dismissal of the dropdown on item select and would also like it to not replace the edit box. How can I achieve this ?
Overriding
replaceText
without callingsuper
works fine (prevents entering suggested text intoAutoCompleteTextView
), but overridingdismissDropDown
causes not-dismissing dropdown not only when item clicked, but also whenonBackPressed
, touched outside dialog etc...I've ended with NOT using
setOnItemClickListener
method fromAutoCompleteTextView
at all. I'm creating custom onClick in my customArrayAdapter
and set it for allView
s returned bygetView
methodin fact setting onClick for whole view will cover "original" always-dismissing and always-replacing-text onClick (not called at all then). Remember about adding custom graphic representation, when pressed (ripple/selector are shown when "original" onClick called only)
I've needed also always-visible functionality, because my autocomplete must always show first position (functional), even when there is no suggestions (if present then shown below on positions 1+)
when
AlwaysVisibleAutoCompleteTextView
is focused, but dropdown dismissed and user pressview
again, then dropdown is not showing, because focus state not changing (onFocusChanged
not called), soIf you aren't planning using
setOnTouchListener
for yourAutoCompleteTextView
for any other purpose, thenOnTouchListener
may be set insideAlwaysVisibleAutoCompleteTextView
class (in every constructor)well at least it seems like they are planning to add this in near future.
First Question - Prevent dropdown dismissal:
Solved below.
Second Question - Prevent text replacement: (For others interested)
You can extend AutoCompleteTextView and override
to do nothing.
As others mentioned, overriding performCompletion() won't help here.
edit,new answer: this worked for me but it closes for a sec,and opens again.
I added an onClickListener to the entire custom row layout that I was using for the dropdown adapter. This way whenever the row is clicked, my row onClickListener is invoked and the default one for the dropdown is not.
I also want to implement the same i used below code to implement it.
Create a custom class and extend AutoCompleteTextView.
Override dismissDropDown() method and remove the super call from it. Will work for you.