简体   繁体   English

如何在android中实现搜索栏?

[英]How can implement search bar in android?

I am working in android. 我在android工作。 i am trying to display name of university using listView. 我正在尝试使用listView显示大学名称。

my list view is looking like this. 我的列表视图看起来像这样。 在此输入图像描述

Now i want to add a search bar on the top of this list view. 现在我想在此列表视图的顶部添加一个搜索栏。 if i press A in search bar then this list view should display all the name of university start with A , if i press some other character then according university name must be displayed. 如果我在搜索栏中按A ,则此列表视图应显示大学以A开头的所有名称,如果我按其他字符则必须显示大学名称。

Please tell me how can implement this. 请告诉我如何实现这一点。 Is any way to make search bar in android. 有没有办法在android中制作搜索栏。 I have seen in iPhone, it works very efficiently in iPhone. 我在iPhone上看到过,它在iPhone中非常有效。 Please help me how can make this search bar ? 请帮帮我怎么做这个搜索栏?

Thank you in advance... 先感谢您...

This may be the long way. 这可能是漫长的道路。 but this is just an idea.. 但这只是一个想法..

I think you have to create a layout xml file with one EditText and ListView . 我认为你必须使用一个EditTextListView创建一个布局xml文件。 Inside activity you have to listen for textChange in EditText and then probably you have to filter your ListAdapter based on the text entered by the user and bind it with ListView . 在Inside活动中你必须在EditText监听textChange,然后你可能需要根据用户输入的文本过滤ListAdapter并将其与ListView绑定。

See the complete example here : http://www.androidpeople.com/android-listview-searchbox-sort-items 请参阅此处的完整示例: http//www.androidpeople.com/android-listview-searchbox-sort-items

您可以在列表视图中使用setTextFilterEnabled(true)

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

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