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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
...
private Button m_sol1, m_sol2, m_sol3;
...
private View.OnClickListener buttonListener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Button b = (Button) v;
// Correct response.
if (m_currentQuestion.getCorrect().equals(b.getText()))
{
b.getBackground().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY);
// Lock button during the wait.
lock(true);
// Wait for new question.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
newQuestion();
}
}, 500);
}
// Bad response.
else
{
b.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
// Lock usage of bouton.
lock(true);
// Colorise the good response.
if (m_currentQuestion.getCorrect().equals(m_sol1.getText()))
{
m_sol1.getBackground().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY);
}
else if (m_currentQuestion.getCorrect().equals(m_sol2.getText()))
{
m_sol2.getBackground().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY);
}
else
{
m_sol3.getBackground().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY);
}
// wait 1 sec before lauch newQuestion.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
newQuestion();
}
}, 1000);
}
}
}; |