Ext.: http://www.cnblogs.com/tianjian/archive/2011/12/15/2289143.html
Hello everyone, about Android double-click event I believe we all know that there is a method in the API, but it must be used in the activity.
For the end use of Android double-click event API each has a different view.
Using the API in activity
Advantages: Save time and effort, other people write things, direct use on the line, do not worry about the bug
Cons: Code writing always feels a little messy in the activity.
Write yourself a OnDoubleClick method
Advantages: Write your own things, good control, flexibility, where you want to put.
Cons: It takes time to check for bugs and things like that.
Well, lately I've also had a problem with double-click events, and that's what I'm dealing with.
I use the Android API but I'm also good at sorting it out.
On the code bar, there are only 2 classes one of course the activity another is the OnDoubleClick event handler class
1Import android.app.Activity;
2Import Android.os.Bundle;
3Import Android.view.GestureDetector;
4Import android.view.MotionEvent;
5Import Android.view.View.OnTouchListener;
6
7/**
8*
9* <p>class instruction: Internal interface core activity</p>
10* Create in 2011-12-2@authorMercury
11*/
12PublicClass GameactivityExtends Activity {
Gameactivityhelper Helper;
14Private Gesturedetector GD;
@Override
16Publicvoid OnCreate (Bundle savedinstancestate) {
17Super.oncreate (savedinstancestate);
18 helper=new gameactivityhelper (this);
19 helper.init ();
20 Setcontentview (Helper.getgameview ());
21 gd=new Gesturedetector ( this,new OnDoubleClick ());
22}
23 @Override
24 public boolean Ontouchevent (Motionevent event) {
25 return Gd.ontouchevent (event);
26}
27}
1Import Android.view.GestureDetector;
2Import android.view.MotionEvent;
3
4PublicClass OnDoubleClickExtends gesturedetector.simpleongesturelistener{
5 @Override
6PublicBoolean Ondoubletap (Motionevent e) {
7 //todo
8 return false;
9}
10 // @Override
11 // public Boolean ondoubletapevent (Motionevent e) {
12 //< Span style= "color: #008000;" > return super.ondoubletapevent (e);
13 //}
14}
The code is also neat. There are two types of processing in the API for double-click
One is to double-click and execute once: Ondoubletap
One is to double-click after the execution two times: ondoubletapevent
Here, I just need to double-click and execute once, and there's a comment out there.
There is also a need to pay particular attention to the way in which the parent activity is overridden in its own activity
@Override
public boolean ontouchevent (Motionevent event) {
Return Gd.ontouchevent (event);
}
This method. I see a lot of people in the activity in the implementation of implements Ontouchlistener will require you to rewrite the Ontouch method to achieve double-click.
This is completely misleading practice, I personally tried, double-click is invalid, normal Click or valid I was in the SDK1.6 version of the trial
This is a detail that I hope you will pay more attention to.
The ontouchevent here is the method in the activity, not the implementation of an interface, which is why the double-click event can only be handled in the activity,
If you need to handle the double-click event with ANDROIDAPI, you must rewrite the Ontouchevent method in the activity otherwise the methods associated with Gesturedetector are not valid
OnTouch can not implement gesturedetector functions as long as the view or activity of the Ontouchlistener interface must be overridden.
About Android Double-click events