jp1017 / Android-Collection

安卓开发知识点集锦
21 stars 11 forks source link

辨别单击,双击,三击 #32

Open jp1017 opened 7 years ago

jp1017 commented 7 years ago

From: https://github.com/android-cn/android-discuss/issues/324

 private long[] mHits = new long[3];// 数组长度表示要点击的次数

//android setting 中点击版本的代码例子
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();// 开机后开始计算的时间(开机时间)
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            //几次点击的逻辑
        }
    }
});