2

我的安卓有问题。当您使用 AutoCompleteTextView 时:

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.entry);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.url_addresses);

String[] url_addresses = getResources().getStringArray(R.array.url_addresses);
for (String string : url_addresses) {
    adapter.add(string);
}

textView.setAdapter(adapter);
.....

当您在文本框中输入“google”关键字时,自动完成系统显示所有以“google”开头的网址。例如:

  • google.com
  • google.com.tr
  • google.co.uk

但是,我想显示包含“google”的网址。例如:

  • http://www.google.com/
  • https://mail.google.com/
  • http://another.google.com/

我认为如果 item 不包含任何空格(一个单词,如 url),就会出现此问题。

有可能的?

非常感谢。

4

2 回答 2

0

That should be simple. Wrap the url string into another class and in toString return the url with dots replaced with spaces. For example, The url http://mail.google.com will be returned as http://mail google com which will be matched easily by the filter. You can replace other characters also similarly before returning the string seperated by spaces. Like //

class urlString {

   String url;
   public String toString() {
       return url.replace('.',' ');// replace dots with space
   }
}
于 2011-09-17T14:36:27.130 回答
0

IIRC,编写您自己的适配器,而不是使用基本的 ArrayAdapter。请参阅 Filter.performFiltering...带有自定义适配器过滤的 Android AutoCompleteTextView 不起作用

于 2014-05-14T11:47:51.170 回答