Android Events and event listeners

Source: Internet
Author: User

There are several common event listeners in the Android system:

1. Click event (View.onclicklistener): This event occurs when the user touches a component or the key is pressed, and the event is handled by the onclick ().

2. Focus event (View.onfocuschangelistener): This event occurs when the component Gets or loses focus, and the event handling method is Onfocuschange ().

3, key event (View.onkey Listener): When the user presses or releases a key on the device, the event handling method is OnKey ().

4, Touch Event (View.ontouchlistener): When the device has a touch screen function, touch the screen to produce the event. The event handling method is Ontouch ().

5. Create context menu event (View.oncreatecontextmenu Listener): This event is generated when the context menu is created, and the event handling method is Oncreatecontextmenu ().


Event Processing steps:

1, create the event supervisor.

2. Register the event supervisor with the component to respond to the event.

3, write the implementation code in the event handling method.


Common events and listeners and their implementation code:

Key Events:

Button.setonclicklistener (New Onclicklistener () {public void OnClick (View arg0) {//...}});

Focus Event:

Text.setonfocuschangelistener (New Onfocuschangelistener () {public void Onfocuschange (View arg0, Boolean arg1) {//. .....    }});

Select event for Multi box :

Checkbox.setoncheckedchangelistener (New Oncheckedchangelistener () {public void oncheckedchanged (Compoundbutton arg0 , Boolean arg1) {//...}});




This article is from the "Useless Uncle" blog, please be sure to keep this source http://aslonely.blog.51cto.com/6552465/1614895

Android Events and event listeners

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.