diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 54b6cfa9a9e5b861a9930af873580d6dc20f773c (patch) | |
tree | 35051494d2af230dce54d6b31c6af8fc24091316 /docs/html/guide/topics/views/ui-events.jd | |
download | frameworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.zip frameworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.tar.gz frameworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.tar.bz2 |
Initial Contribution
Diffstat (limited to 'docs/html/guide/topics/views/ui-events.jd')
-rw-r--r-- | docs/html/guide/topics/views/ui-events.jd | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/html/guide/topics/views/ui-events.jd b/docs/html/guide/topics/views/ui-events.jd new file mode 100644 index 0000000..4230314 --- /dev/null +++ b/docs/html/guide/topics/views/ui-events.jd @@ -0,0 +1,31 @@ +page.title=Handling UI Events +@jd:body + +<p>Many Android classes declare callback methods for handling relevant UI events such as keypresses, touch events, focus changes, and so on. For example, {@link android.app.Activity Activity} provides the methods onKeyDown() and onKeyUp() and {@link android.widget.TextView TextView} provides onFocusChanged(). </p> + +<p>In most cases, you can handle events just by overriding the appropriate handler methods. When an event is received, the Android system calls your handler method with the event data.</p> + +<p>However, some classes do not declare handler methods for specific events. For example, {@link android.widget.Button Button} does not declare an onClick() handler method. To handle such events, you need to create an anonymous class to act as a listener for the event, then register the listener with the target class object. The example below shows how to set up a handler for click events in a Button object. </p> + + + +</p> +<pre>public class ExampleSendResult extends Activity +{ + protected void onCreate(Bundle savedValues) + { + ... + + // Listen for button clicks. + Button button = (Button)findViewById(R.id.corky); + button.setOnClickListener(mCorkyListener); + } + + // Create an anonymous class to act as a button click listener. + private OnClickListener mCorkyListener = new OnClickListener() + { + public void onClick(View v) + { + //handle click event... + } + };</pre> |