private void processClick(int optionClicked) { mTotalTries++; if (mCorrectAnswer == optionClicked) { mCurrentSimulationNumber++; if (mCurrentSimulationNumber == MAX_SIMULATIONS) { long elapsedTime = stopWatch.getElapsedMilliseconds(); currentResult.setElapsedTime(mSimulationType, elapsedTime); currentResult.setErrorPercentage(mSimulationType, 1 - 1.0 * MAX_SIMULATIONS / mTotalTries); stopWatch.restart(); if (mSimulationType == STROOP_EFFECT_INCONGRUENT) { String message = "Thanks for participating."; Toast.makeText(getActivity().getApplicationContext(), message, Toast.LENGTH_LONG).show(); ((MainActivity) getActivity()).insertResultIntoDatabase(currentResult); ((MainActivity) getActivity()).startHomeFragment(); } mSimulationType++; mCurrentSimulationNumber = 0; mTotalTries = 0; } simulate(mSimulationType); } else { errorToast.show(); Handler handler = new Handler(); handler.postDelayed( new Runnable() { @Override public void run() { errorToast.cancel(); } }, TOAST_DURATION); } }