Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

登录注册的按钮没有做防抖吗 #42

Closed
fubd opened this issue Nov 8, 2020 · 2 comments
Closed

登录注册的按钮没有做防抖吗 #42

fubd opened this issue Nov 8, 2020 · 2 comments

Comments

@fubd
Copy link

fubd commented Nov 8, 2020

使用databinding时,防抖应该怎么实现

@fubd
Copy link
Author

fubd commented Nov 8, 2020

@hegaojian

@hegaojian
Copy link
Owner

百度搜搜,代码一大堆哦 兄待

 @BindingAdapter("noRepeatClick")
    @JvmStatic
    fun setOnClick(view: View, clickListener: () -> Unit) {
        val mHits = LongArray(2)
        view.setOnClickListener {
            System.arraycopy(mHits, 1, mHits, 0, mHits.size - 1)
            mHits[mHits.size - 1] = SystemClock.uptimeMillis()
            if (mHits[0] < SystemClock.uptimeMillis() - 500) {
                clickListener.invoke()
            }
        }
    }
<TextView
         android:id="@+id/loginSub"
         android:layout_width="match_parent"
         android:layout_height="48dp"
         android:layout_marginTop="30dp"
         android:layout_marginBottom="12dp"
         android:background="@drawable/button_shap"
         android:gravity="center"
         android:text="登录"
         bind:noRepeatClick="@{() -> click.login() }"
         android:textColor="@color/white"
         android:textSize="16dp" />

@fubd fubd closed this as completed Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants