Problems covered in this chapter |
|
In Chapter 7 we defined the toolbar menu (file menu_toolbar.xml). In the last chapter we activated the Help and Preferences menu items when the user is at the home screen of our app. In the toolbar menu we also defined a search view which we will activate in this chapter so the user can search items in the corresponding lists. You will be surprised - it takes only a couple of additional lines and we are done! We simply extend MainActivity and we can search persons and tags:
When you install the app to a (virtual) device, you will spot a magnifying glass on top of the persons and tags lists (see Figure 17.1).
When you tap on the magnifying glass and enter a search term, the list is narrowed to items matching your term (see Figure 17.2).
If you enter a search term that none of your items matches, you get a corresponding message (see Figure 17.3).
When you search tags, your search term is matched with tag titles. However, if you search persons, your search term matches the person’s name as well as the person’s birthdate. Give it a try!