简体   繁体   English

Android AutoCompleteTextbox

[英]Android AutoCompleteTextbox

I am trying to implement a functionality like Twitter: when user type in '@', a dropdown menu shows-up with some suggestions. 我正在尝试实现类似Twitter的功能:当用户键入“ @”时,将显示一个带有一些建议的下拉菜单。

Here's my current code: 这是我当前的代码:

mTextBox = (AutoCompleteTextView) findViewById(R.id.text);
String[] testArray = {"aaa", "aabc", "aaaa", "bbb" , "bcd", "zzz", "fff", "ndc"};

ArrayAdapter<String> adapter = 
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testArray);

adapter.setNotifyOnChange(true);

mTextBox.setAdapter(adapter);

Currently, the behavior of the AutoCompleteTextView is, when I type in part of the word, the full suggestion shows up. 当前,当我键入单词的一部分时,AutoCompleteTextView的行为将显示完整建议。 For example, when I type in a , it shows nothing, when I type in aa , then it shows suggestion of aabc , aaa and aaaa . 例如,当我输入a ,什么都不显示,当我输入aa ,则显示aabcaaaaaaa建议。

How can I make it so when I type in @ , it shows a list of all available options? 当我输入@ ,如何显示所有可用选项的列表?

Thank you 谢谢

将以下属性添加到xml文件的AutocompleteTextView中

android:completionThreshold="1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM