键入时 Android 搜索列表 [英] Android search list while typing

查看:23
本文介绍了键入时 Android 搜索列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何构建一个搜索栏,以便在我输入时将结果显示在我正在搜索的 ListView 中?

How can I build a search bar where while I'm typing the results are shown in the ListView in which I'm searching?

例如,我有一个包含 20 个字符串的列表视图.我按下搜索键并出现栏.我希望当我输入 3 个或更多单词时,搜索开始运行,在列表视图中显示结果(作为过滤器:只显示列表中与我输入的内容匹配的字符串)

For example, I have a list view with 20 strings. I press the search key and appears the bar. I want when I type 3 words or more the search starts running showing the results in the list view (as a filter: only shows the strings in the list that matching what I type)

推荐答案

您无法使用搜索栏执行此操作.但列表视图有可能过滤按键,就像在联系人中所做的那样.用户只需开始输入,然后列表就会被过滤.过滤并不像搜索.如果您的列表在某处包含单词 foo 并且您键入 oo foo 将被过滤掉,但是如果您键入 fo 它会保留,即使列表项是 call bar foo.

You can't do this with the search bar. But the listview has a possibility to filter on key pressed, like it is done in the contacts. The user simply starts typing and the list gets filtered then. Filtering is not really like searching. If you list contains the word foo somewhere and you type oo foo will be filtered out, but if you type fo it will stay even if the list item is call bar foo.

您只需启用它:

ListView lv = getListView();
lv.setTextFilterEnabled(true);

如果您没有硬件键盘,我不知道这是如何完成的.我正在使用机器人并开始输入开始列表以进行过滤并仅显示匹配的结果.

I don't know how this is done if you don't have a hardware keyboard. I'm using the droid and starting to type starts the list to filter and to show only matching results.

这篇关于键入时 Android 搜索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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