Книга: Beginning Android

Handling Screen Taps

Handling Screen Taps

An Overlay subclass can also implement onTap(), to be notified when the user taps on the map, so the overlay can adjust what it draws. For example, in full-size Google Maps, clicking on a push-pin pops up a bubble with information about the business at that pin’s location. With onTap(), you can do much the same in Android.

The onTap() method for ItemizedOverlay receives the index of the OverlayItem that was clicked. It is up to you to do something worthwhile with this event.

In the case of SitesOverlay, as previously shown, onTap() looks like this:

protected boolean onTap(int i) {
  items.get(i).getSnippet(), Toast.LENGTH_SHORT).show();

Here, we just toss up a short Toast with the “snippet” from the OverlayItem, returning true to indicate we handled the tap.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.106. Запросов К БД/Cache: 3 / 1
Вверх Вниз