AutoCompleteTextView空间导致空 [英] AutoCompleteTextView results empty on space

查看:120
本文介绍了AutoCompleteTextView空间导致空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AutoCompleteTextView,它工作得很好,直到我添加一个空格到我的输入。如果我有,说,许多历史事件的列表(不列颠之战(1940),价格猛涨(1944)之战,[插入大量的战斗],拿破仑的死亡行军(1812),[插入其他很多历史事件])

I have an AutoCompleteTextView, and it works nicely, until I add a space to my input. If i had, say, a list of many historical events (Battle of Britain (1940), Battle of the Bulge (1944), [insert lots of battles], Napoleon's fatal march (1812), [insert lots other historical events]).

当我进入战斗或战斗,我得到的所有战斗的列表(虽然它似乎还有一个最大),当我进入英国达人中,不列颠之战(1940年)出现在结果。然而,当我的战斗之后输入一个空格,所有的结果项消失了。

When I enter "Battle" or "battle", I get a list of all battles (although it seems there is a max), and when I enter "britain", the "Battle of Britain (1940)" appears in the results. However, when I enter a space after "Battle", all result entries disappear.

我看了真的不能找到有关除了<一此主题的任何有帮助的帖子或问题href=\"http://stackoverflow.com/questions/8233262/autocompletetextview-doesnt-recognize-spaces\">this,但是这并没有给我任何答案。

I read can't really find any helpful posts or questions regarding this topic besides this, but that didn't give me any answers.

有没有办法有AutoCompleteTextView保持自动填充空间的插入后?

Is there a way to have the AutoCompleteTextView keep autocompleting after the insertion of a space?

修改:我实在不明白加code的点,因为它只是与弦乐的适配器的AutoCompleteTextView,不过还好,这种情况发生在的onCreate()

Edit: I don't really see the point of adding code, as it's just an AutoCompleteTextView with an Adapter with Strings, but alright, this happens in onCreate():

auto = (AutoCompleteTextView) findViewById(R.id.auto);
String[] events = getListOfEvents();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, events);
auto.setAdapter(adapter);

其中, getListOfEvents()只是读取把所有的历史事件在的String []

where getListOfEvents() simply reads an puts all historical events in a String[]

推荐答案

自动插入的空格字符时,因为引擎盖下它使用的过滤器从正在​​对 AutoCompleteTextView <设置适配器完全断裂/ code>(<你的情况code> ArrayAdapter )。默认 ArrayAdapter 过滤器使用空格作为分隔符到每个适配器的行的文本分解成单词然后将其对滤波器输入测试。这将提供没有结果,因为输入滤波器(其中有一个空格),则它不会从行匹配任何的单词(如那些话没有结尾的空间)。例如该行的不列颠之战的不匹配的战役的原因的战役的将不符合任何话的 战斗英国达人的从后。

The auto complete breaks when inserting that space character because under the hood it uses the filter from the adapter that is set on the AutoCompleteTextView(ArrayAdapter in your case). The filter for the default ArrayAdapter uses spaces as a delimiter to break the text of each adapter's row into words which are then tested against the filter input. This will provide no results because the input filter(which has a space in it) will not match any of the words from the row(as those words don't have the space at the end). For example the row "Battle of Britain" will not match "Battle " because "Battle " will not match any of the words "Battle", "of" or "Britain" which result from splitting the initial text after " ".

如果你想它的工作,你必须实现自己的适配器将返回一个过滤器在考虑接受一个单词后空间。

If you want to make it work you'll have to implement your own Adapter which will return a Filter that takes in consideration that space after a word.

这篇关于AutoCompleteTextView空间导致空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆