Android The operating system, for the event handling is a very basic and important operation. The realization of many of the features needed to trigger the relevant events in order to achieve their own objectives. Such as Android event listener is a view View class interface that contains a single callback method. These methods will be in the view of the listener has been registered in the user interface action is triggered by the Android framework of the call. The following callback methods are included in the Android event listener interface:

onClick ()

Included in the View.OnClickListener. When the user touch the item (in the touch mode), or by browsing key or trackball focus on this item, then press the "confirm" button or press the track ball is called.

onLongClick ()

Included in the View.OnLongClickListener. When the user touch and do something about the item (in the touch mode), or by browsing key or trackball focus on this item, and then keep pressing the "confirm" button or press the track ball (one second) is called.

onFocusChange ()

Included in the View.OnFocusChangeListener. When the user use the browse button or follow the ball here when you enter or leave the item is called.

onKey ()

Included in the View.OnKeyListener. When the user focus on this item and press or release a button when the device is called.

onTouch ()

Included in the View.OnTouchListener. When the user performs the action be treated as a touch event is called, including the press, release, or move any gestures on the screen (within the boundary of this item).

onCreateContextMenu ()

Included in the View.OnCreateContextMenuListener. When is creating a context menu when they were called (as a continuous "long click" action of the results). See the section Creating Menus Creating the menu for more information.

These methods are their corresponding interface, the only "household." To define these methods and handle your event, in your activities to achieve this nested interface or define it as an anonymous class. Then, pass an instance of your implementation to the respective View.set ... Listener () method. (Eg, call setOnClickListener () and pass to it your OnClickListener met).

The following example shows how to register a click on a button listener:

/ / Create an anonymous implementation of OnClickListener

private OnClickListener mCorkyListener = new OnClickListener () (

public void onClick (View v) (

/ / Do something when the button is clicked

)

);

protected void onCreate (Bundle savedValues) (

...

/ / Capture our button from layout

Button button = (Button) findViewById (R.id.corky);

/ / Register the onClick listener with the implementation above

button.setOnClickListener (mCorkyListener);

...

)

You may find the OnClickListener as part of the activities to achieve would be more convenient. This will avoid additional class loading and object distribution. For example:

Note that the above example, the onClick () callback does not return value, but some other Android event listener must return a boolean value. And event-related causes. For some of the following reasons:

· OnLongClick () - returns a Boolean value to indicate whether you have consumed this incident should not be further process it. In other words, returns true that you have dealt with this incident, and stop there; return false that you do not deal with it and / or this event should continue to be passed on to other on-click listener.

· OnKey () - returns a Boolean value to indicate whether you have consumed this incident should not be further process it. In other words, returns true that you have dealt with this incident, and stop there; return false that you do not deal with it and / or this event should continue to be passed on to other on-key listener.

· OnTouch () - returns a Boolean value to indicate whether your listener consumes the event. Important is that this event can have more than each other to follow the action. So, if it receives action events you back down to false, it shows that you have not consumption, but also for the follow-up action in this incident is not interested. So, you will not be the case in the other action is called, such as gestures or the last upward movement event occurs.

Remember that key event is always submitted to the current focus of view. View them from the top of the hierarchy began to be distributed, and then turn downward, until you reach the appropriate target. If you view (or a sub-view) currently has the focus, then you can see the event through the dispatchKeyEvent () methods of distribution. Apart from your view of intercept key events, there is an option, you can use in your activities onKeyDown () and onKeyUp () to receive all events.

NOTE: Android will be the first event handler is called, followed by the default class definition in the appropriate processor. Thus, from these things return true listener will stop the event listener to other Android event will be transmitted and blocking the view of the lack of event-handler callback function. So when you return true, make sure you want to terminate the incident.

Persistence of three main points: 1, a statement for persistent fields accessors (accessors) and whether the variable signs (mutators) Property statement is not necessarily required for the public's. Hibernate can be default, protected or private ...

The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

The first is the company give you a chance to meet, it is necessary to know to meet from time to equal the interview, and have a lot of companies to see you at the first time will give you a ready point of doing something trivial, these questions, althoug

Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...