0
votes

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(MainActivity.this,R.layout.activity_main); setContentView(binding.getRoot()); binding.textView.setTextSize(18); for (int i = 0; i < questionBank.length;) { Questions questions = questionBank[i]; binding.textView.setText(questions.getAnswerResId()); binding.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (questions.isAnswerTrue()) { Toast.makeText(MainActivity.this, R.string.correct_answer, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, R.string.wrong_answer, Toast.LENGTH_SHORT).show(); } } });

        binding.button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!questions.isAnswerTrue()) {
                    Toast.makeText(MainActivity.this, R.string.correct_answer, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, R.string.wrong_answer, Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    


}
1

1 Answers

0
votes

No need for

setContentView(binding.getRoot());

DataBinding.setContentView() is enough.