1、
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:onClick="click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="双击事件" />
</RelativeLayout>
2、
public class MainActivity extends Activity {
long firstClickTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view){
if(firstClickTime>0){
long sencondClickTime = SystemClock.uptimeMillis();
long dtime = sencondClickTime - firstClickTime;
if(dtime<500){
Toast.makeText(this, "双击了", 0).show();
}else{
firstClickTime = 0;
}
return;
}
firstClickTime = SystemClock.uptimeMillis();
new Thread(){
public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
firstClickTime = 0;
};
}.start();
}
}