I am here of course ignoring the fact that there are more than a hundred apps similar available on the Market.
When developing the first version of this app I ran into an interesting point about UI responsiveness and how I could do a "sleep()" function.
The flow is:
- The problem is presented
- The user answers by clicking on of the available buttons
- Mark the problem green for a second before continuing if the answer was correct
- If the asnwer was incorrect mark the problem red until the correct answer is chosen
I ended up doing it as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | private void verifyResult( final View view){ answerAttempts++; // The user has tried to answer the problem increment answer attempts disableAnswerButtons(); // Disable further user input when the text is green/red otherwise the user can click many times on the buttons int result = Integer.parseInt(view.getTag().toString()); if (correctResult == result) { problem.setTextColor(Color.GREEN); problem.setText(getProblemText( true )); // Show full problem + correct result points++; // Wait 1 second before resetting the text color and showing a new problem text new Handler().postDelayed( new Runnable() { public void run() { problem.setTextColor(Color.WHITE); generateProblem(); // Generate a new problem and update UI enableAnswerButtons(); } }, 1000 ); } else { problem.setTextColor(Color.RED); enableAnswerButtons(); } score.setText(String.format( "%s %d/%d" , getString(R.string.score), points, answerAttempts)); } |
No comments:
Post a Comment