哥们点个赞再走呀
制作不容易,条件允许情况下,打赏一下,谢谢
项目build.gradle
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
加入作者的依赖,其中用户名就是作者的微信
implementation 'com.github.nihaoxj123:rCode:1.1.6'
使用方法
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(new OnClickLimitListener() {
@Override
public void click(View v) {
Toast.makeText(MainActivity.this, "哈哈", Toast.LENGTH_SHORT).show();
}
});
//或
findViewById(R.id.btn).setOnClickListener(new OnClickLimitListener(5000) {
@Override
public void click(View v) {
Toast.makeText(MainActivity.this, "哈哈", Toast.LENGTH_SHORT).show();
}
});
}
}
作者亲自想出来的,觉得不好在下面留言,觉得好的可以给作者打赏一下,制作也不容易
public abstract class OnClickLimitListener implements View.OnClickListener {
private long delay; //让用户延时多次时间点击,单位毫秒
private long time; //上次点击时间
public OnClickLimitListener() {
this(500);
}
public OnClickLimitListener(long delay) {
setDelay(delay);
}
public void setDelay(long delay) {
if (delay < 0){
delay = 500;
}
this.delay = delay;
}
@Override
public final void onClick(View v) {
long nowTime = System.currentTimeMillis();
if (nowTime >= time + delay){
click(v);
time = nowTime;
}
}
public abstract void click(View v);
}
网友评论