AutoCompleteTextView hints in landscape mode

僤鯓⒐⒋嵵緔 提交于 2019-12-06 04:38:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!