Android 记事本教程 - 实现搜索功能
我已经从各种书籍和教程中学习 Android 编程大约 4-5 个月了,并且对 Android 编程中的大部分内容有了基本的了解,最近我开始使用 记事本教程,现在练习 3 后就有了最终应用程序
。我想将搜索功能添加到我的应用程序中。这样就可以搜索存储在数据库中的笔记,即在所有笔记的正文部分中检查作为搜索查询给出的单词,然后仅列出包含该特定单词的那些笔记。
您能否建议对现有代码进行一些修改,或者建议实现此搜索功能需要什么? 如何为此修改 SQLite 查询? 或者我应该在将所有笔记的主体存储在字符串数组中后使用Java的indexof()方法?然后使用 for 循环和 if 条件以及 indexof() 方法显示数组的这些元素?
I have been learning Android programming from various books and tutorials from roughly 4-5 months now and have a basic idea of most of the things in Android Programming and I recently started with the Notepad Tutorial and now have the final application after Exercise 3.
I want to add the search feature to my app. So that the notes that are stored in the database can be searched i.e. a word given as search query is checked in the body section of all the notes and then only those notes are listed which contain that specific word.
Please can you suggest some modifications in the existing code or suggest what will be needed to implement this search feature?
How can the SQLite query be modified for this?
or should I use indexof() method of Java after storing the body of all the notes in a String Array? and then just displaying those elements of the array using the for loop and if condition with the indexof() method??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将其与 Android 的搜索框架集成
http://developer.android.com/指南/主题/搜索/index.html
You should integrate this with Search Framework of Android
http://developer.android.com/guide/topics/search/index.html