Issue
I've made an app and now the idea is that the color of a button changes, that already works, but now I'd like to change the color of the button back to the color that is was. Here is my code:
if (mQuestionNumber == QuestionLibrary.mQuestionsFrankrijk.length) {
Intent i = new Intent(QuizActivityFrankrijk.this,
QuizResultaat.class);
Bundle bundle = new Bundle();
bundle.putInt("finalScore", mScoreFrankrijk);
i.putExtras(bundle);
QuizActivityFrankrijk.this.finish();
startActivity(i);
} else {
view.setBackgroundResource(R.drawable.button_fout);
Toast.makeText(QuizActivityFrankrijk.this, "Fout", Toast.LENGTH_SHORT).show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
view.setBackgroundResource(R.drawable.button_bg_rounded_corners);
updateQuestion();
}
}, 10000);
updateQuestion();
}
And the error is that the view of
view.setBackgroundResource(R.drawable.button_bg_rounded_corners);
is accessed from within inner class and it needs to be declared final, but I don't know how to do that
Solution
to answer your question directly:
...
Handler handler = new Handler();
final View finalView = view;
handler.postDelayed(new Runnable() {
@Override
public void run() {
finalView.setBackgroundResource(R.drawable.button_bg_rounded_corners);
updateQuestion();
...
Answered By - Frank
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.