Craft the Search Activity

 

The first thing you’ll want to do if you want to support query‑style search in your application is to create a search activity. While it might be possible to have a single activity be both opened from the launcher and opened from a search, that might prove somewhat confusing to users. Certainly, for the purposes of learning the techniques, having a separate activity is cleaner.

The search activity can have any look you want. In fact, other than watching for queries, a search activity looks, walks, and talks like any other activity in your system.

All the search activity needs to do differently is check the intents supplied to (via ) and to see if one is a search, and, if so, to do the search and display the results.

For example, let’s look at the sample application (available in the Source Code section of http://apress.com). This starts off as a clone of the list‑of‑lorem‑ipsum‑words application that we first built back when showing off the container in Chapter 8, then with XML resources in Chapter 19. Now we update it to support searching the list of words for ones containing the search string.

The main activity and the search activity share a common layout: a plus a showing the selected entry:

 

In terms of Java code, most of the guts of the activities are poured into an abstract class:








Дата добавления: 2015-05-16; просмотров: 819;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.007 сек.