abstract class OnSingleClickListener: View.OnClickListener {
private val MIN_CLICK_DELAY_TIME = 500;
private var mLastClickTime = 0L;
override fun onClick(v: View) {
var curClickTime = System.currentTimeMillis();
if ((curClickTime - mLastClickTime) >= MIN_CLICK_DELAY_TIME) {
mLastClickTime = curClickTime;
onSingleClick(v);
}
}
public abstract fun onSingleClick(v:View)
}
设置点击事件
mBinding.ivAvatar.setOnClickListener(object : OnSingleClickListener() {
override fun onSingleClick(v: View) {
}
})