我已经制作了一个应用程序,现在的想法是按钮的颜色会发生变化,已经有效,但现在我想将按钮的颜色改回原来的颜色。这是我的代码:
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();
}
错误是
的视图view.setBackgroundResource(R.drawable.button_bg_rounded_corners);
是从内部类中访问的,需要声明为final,但我不知道该怎么做
答案 0 :(得分:1)
直接回答你的问题:
...
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();
...