1 组件监听事件,业务逻辑之前判断网络情况
public abstract class OnClickNetworkListener implements View.OnClickListener { @Override public void onClick(View v) { boolean isNetworkOk = Config.isNetworkConnected(Config.currentContext); if (isNetworkOk) { onNetworkClick(v); } else { Toast.makeText(Config.currentContext, SysConfig.NETWORK_FAIL, Toast.LENGTH_SHORT).show(); } } public abstract void onNetworkClick(View v); }
2 组件监听事件,业务逻辑之前判断是否点击过快重复点击
public abstract class OnClickFastListener implements View.OnClickListener{ private static long lastClickTime; public static boolean isFastDoubleClick() { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if ( 0 < timeD && timeD < 500) { return true; } lastClickTime = time; return false; } @Override public void onClick(View v) { if (OnClickFastListener.isFastDoubleClick()) { return; } onFastClick(v); } public abstract void onFastClick(View v); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-08 09:59:30