• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem in Button OnClick

  • Thread starter Thread starter Android Question
  • Start date Start date
A

Android Question

Guest
butNext.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
RadioGroup grp = (RadioGroup) findViewById(R.id.radioGroup1);
RadioButton answer = (RadioButton) findViewById(grp.getCheckedRadioButtonId());


Log.d("yourans", currentQ.getANSWER() + " " + answer.getText());
if (currentQ.getANSWER().equals(answer.getText())) {
Toast.makeText(DeldActivity.this, "Awesome Right Answer.;-)", Toast.LENGTH_SHORT).show();
score++;
Log.d("score", "Your score" + score);
} else {
Toast.makeText(DeldActivity.this, "Wrong Answer.The Right Answer is " + currentQ.getANSWER(), Toast.LENGTH_SHORT).show();
}


if (qid < totalq) {
grp.clearCheck();
currentQ = quesList.get(qid);
setQuestionView();
} else {
Intent intent = new Intent(DeldActivity.this, DeldResultActivity.class);
Bundle b = new Bundle();
Bundle total = new Bundle();
b.putInt("score", score); //Your score
b.putInt("qid", qid);
intent.putExtras(b);
intent.putExtras(total);//Put your score to your next Intent
startActivity(intent);
finish();
}
}

});
}



when I click on the radio button with no button checked the app force stops please give me a solution
 
Move the findviewbyid codes out of the onclick method and try once again.
If you still face problem, do let me know
 
Last edited by a moderator:
Back
Top Bottom