Android Tutorial

(avery) #1
Android Tutorial 203

timer.start();
result = true;
break;
case R.id.reset_timer:
timer.setBase(SystemClock.elapsedRealtime());
result = true;
break;
}
return result;
}


Because we have only one context menu in this example, we find
the Chronometer view for use in this method. This method is called
regardless of which context menu the selected item is on, though,
so you should take care to have unique resource identifiers or keep
track of which menu is shown. This can be accomplished because
the context menu is created each time it’s shown.

Handling User Events

You’ve seen how to do basic event handling in some of the previous
control examples. For instance, you know how to handle when a
user clicks on a button. There are a number of other events
generated by various actions the user might take. This section
briefly introduces you to some of these events. First, though, we
need to talk about the input states within Android.

Listening for Touch Mode Changes

The Android screen can be in one of two states. The state
determines how the focus on View controls is handled. When touch
mode is on, typically only objects such as EditText get focus when
selected. Other objects, because they can be selected directly by
Free download pdf