问题
I'm using AutoCompleteTextView
in my app with a custom adapter and it works perfect in portrait mode. In horizontal mode however the software keyboard takes most of the screen and text view uses overlay buttons instead of Views provided by the adapter.
I couldn't find a clear documentation about how this works behind the scenes. It seems that in landscape mode AutoCompleteTextView
bypasses adapter's getView()
method, does some dirty work using getItem()
and renders items itself using raw strings.
To make things worse it seems that in AutoCompleteTextView
is accualy presenting TWO lists of autocompletion hints: standard dropdown AND overlay buttons in the same time
(this is well visible if we set imeOptions to flagNoExtractUi
to prevent AutoCompleteTextView
expanding in landscape).
I'd like to supply my own Views in BOTH situations - but I managed to do it only for the drop down menu so far. Any changes to provide custom views for overlayed list?
I'm sorry but I can't post images due to low ranking yet. I can send them if anyone needs them.
回答1:
I just encountered this issue myself. Like you said, in landscape the TextView is basing its autocomplete hints on the result of getItem()
. I don't really see a way to provide anything other than text in this scenario, but a simple solution to get the correct text to show in landscape is to override toString()
for the object you are basing the hint on.
For instance, in my scenario I am using a list of Contact objects to populate my autocomplete hints, so I overrode toString()
in my Contact class to get it to show "FirstName LastName" instead of a raw object representation like "Contact@a2a6d4d3a5."
来源:https://stackoverflow.com/questions/11727425/autocompletetextview-hints-in-landscape-mode