android重复点击问题

open class SingleClickListener(private val intervalMils: Long = 1000): OnClickListener{
    private val TAG = this.javaClass.name

    private var mLastClickTime = 0L
    override fun onClick(p0: View?) {
        Logger.logger(TAG, "onClick")
        val ct = TimeUtil.getTimestamp(true)
        if(ct - mLastClickTime > intervalMils){
            mLastClickTime = ct
            onSingleClick(p0)
        }
    }

    open fun onSingleClick(v: View?){}
}

调用

getView<View>(R.id.abc).setOnClickListener(object : SingleClickListener(5000) {
    override fun onSingleClick(v: View?) {
        //TODO
    }
})

 

posted @ 2023-07-31 23:40  乱炖er  阅读(29)  评论(0编辑  收藏  举报