The basis of the event: press, move, lift.
The first thing to do is to press, and the second may be to move, and finally perform the lift.
Android Event delivery mechanism:
Android Event delivery is delivered hierarchically, with event handling from activity to ViewGroup to view.
View and ViewGroup response methods to events (that is, delivery methods):
Dispatchtouchevent (): Distribution of the event. Return true to not continue distribution.
return FALSE to continue distribution at the next level
Ontouchevent (): Handling of the event. Return True indicates consumption handles the current event,
Return false is not processed and is handed to child controls for continued distribution
Onintercepttouchevent (): Interception of events (note: ViewGroup only)
Return true intercepts the current event and does not continue to distribute it to its own ontouchevent for processing.
return false will not intercept, continue to pass.
1.onTouch event to be executed before the OnClick event
2.onTouch is called in the event distribution method Dispatchtouchevent,
3. The onclick is called in the event-handling method Ontouchevent
4.onTouchEvent () After the call to the Dispatchtouchevent method
Small case: Double-click to exit
/*
* Double Exit Principle:
* Judging by a variable,
* handler.postdelayed (): How long after the delay to restore the original state of the variable
*/
Boolean is2callback=false;
@Override
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode==keyevent.keycode_back) {
if (!is2callback) {
Is2callback=true;
Toast.maketext (Mainactivity.this, "Click again to exit", Toast.length_short). Show ();
New Handler (). postdelayed (New Runnable () {
public void Run () {
Is2callback=false;
}
}, 3*1000);
}
else{
Android.os.Process.killProcess (Android.os.Process.myPid ());
}
}
return true;
}
Android Event delivery mechanism