為了防止用戶或者測試MM瘋狂的點擊某個button,寫個方法防止按鈕連續點擊。具體實例代碼如下所示:
public class BaseActivity extends Activity { protected boolean isDestroy; //防止重復點擊設置的標志,涉及到點擊打開其他Activity時,將該標志設置為false,在onResume事件中設置為true private boolean clickable=true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); isDestroy=false; requestWindowFeature(Window.FEATURE_NO_TITLE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } @Override protected void onDestroy() { super.onDestroy(); isDestroy=true; } @Override protected void onResume() { super.onResume(); //每次返回界面時,將點擊標志設置為可點擊 clickable=true; } /** * 當前是否可以點擊 * @return */ protected boolean isClickable(){ return clickable; } /** * 鎖定點擊 */ protected void lockClick(){ clickable=false; } @Override public void startActivityForResult(Intent intent, int requestCode, Bundle options) { if(isClickable()) { lockClick(); super.startActivityForResult(intent, requestCode,options); } } } 通過一段簡單的代碼給大家介紹了Android解決按鈕重復點擊問題,希望大家喜歡。
新聞熱點
疑難解答
圖片精選