private Button button;
private long startTime;
button = (Button)findViewById(R.id.btn_hello);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//两次点击在一定的时间间隔内,才是双击
if(startTime!=0){
long endTime = System.currentTimeMillis();
//通过判断来控制两次点击的时间差控制范围
Log.i("tag", "startTimeonClick: "+startTime);
Log.i("tag", "endTimeonClick: "+endTime);
if(endTime-startTime<500){
Toast.makeText(getApplicationContext(), "点击2次", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "点击1次", Toast.LENGTH_LONG).show();
}
}
startTime = System.currentTimeMillis();
}
});
}