Skip to content

eriffanani/PreventDoubleClick

Repository files navigation

Prevent Double Click

Avoid your click view from double click which will produce a bug.

Installation

repositories

maven { url 'https://jitpack.io' }

dependencies

implementation 'com.github.eriffanani:PreventDoubleClick:1.0.0'

How To Use

  • Java
new PreventDoubleClick(() -> {
    // TODO ACTION
});
  • Kotlin
PreventDoubleClick {
    // TODO ACTION
}

Output

  • Normal Button

  • Prevent Double Click

Custom Interval

The button can be re-clicked after the specified interval is completed. The default interval is 600 milliseconds.

  • Java
long interval = 1000L; // 1 seconds
new PreventDoubleClick(interval, () -> {
    // TODO ACTION
});
  • Kotlin
val interval = 1000L // 1 seconds
PreventDoubleClick(interval) {
    // TODO ACTION
}

Example use

  • Java Function
public void onClickMyButton() {
    new PreventDoubleClick(() -> {
        // TODO ACTION
    });
}
  • Java View Click Listener
myButton.setOnClickListener(view -> {
    new PreventDoubleClick(() -> {
        // TODO ACTION
    });
});
  • Kotlin Function
fun onClickMyButton() {
    PreventDoubleClick {
      // TODO ACTION
    }
}
  • Kotlin View Click Listener
myButton.setOnClickListener {
    PreventDoubleClick {
      // TODO ACTION
    }
}

Licence

Copyright 2022 Mukhammad Erif Fanani

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Avoid your click view from double click which will produce a bug

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors