Answer the question
In order to leave comments, you need to log in
How to disable a button?
Hello, I've run into this problem.
I have three buttons, on each I have a dawn and up touch handler, after releasing my finger from the button, the thread falls asleep to me, then the function that updates them should start. At this time, if you press the button and release it again, the thread falls asleep again, that is, an endless dream of the thread is obtained.
switch (view.getId()) {
case R.id.answer1:
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int trueNum = 0;
for (int i = 0; i < 15; i++) {
if (text1.equals(questions.getTrueList(i))) {
answer1.setBackgroundDrawable(getDrawable(R.drawable.button_levels_true));
trueNum = 1;
}
}
if (trueNum == 0) answer1.setBackgroundDrawable(getDrawable(R.drawable.button_levels_false));
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
changeQuestion();
}
break;
case R.id.answer2:
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int trueNum = 0;
for (int i = 0; i < 15; i++) {
if (text2.equals(questions.getTrueList(i))) {
answer2.setBackgroundDrawable(getDrawable(R.drawable.button_levels_true));
trueNum = 1;
}
}
if (trueNum == 0) answer2.setBackgroundDrawable(getDrawable(R.drawable.button_levels_false));
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
changeQuestion();
}
break;
case R.id.answer3:
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int trueNum = 0;
for (int i = 0; i < 15; i++) {
if (text3.equals(questions.getTrueList(i))) {
answer3.setBackgroundDrawable(getDrawable(R.drawable.button_levels_true));
trueNum = 1;
}
}
if (trueNum == 0) answer3.setBackgroundDrawable(getDrawable(R.drawable.button_levels_false));
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
changeQuestion();
}
break;
}
return true;
}
};
public void changeQuestion() {
answer1.setBackgroundDrawable(getDrawable(R.drawable.button_levels));
answer2.setBackgroundDrawable(getDrawable(R.drawable.button_levels));
answer3.setBackgroundDrawable(getDrawable(R.drawable.button_levels));
questionText.setText(questions.getQuestion());
text1 = questions.getAnswer1();
text2 = questions.getAnswer2();
text3 = questions.getAnswer3();
answer1.setText(text1);
answer2.setText(text2);
answer3.setText(text3);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question