I am writing a multi-choice quiz using the Eclipse for Android with 4 buttons for possible answers.
In the It should send a string called Answer which declares which button was pressed - is it really happening? I have the following code in the When the button is pressed, the reply sent should be obtained with the intention - will it work? I want to add a condition that the value of "Answer" is equal to the global variable for the Thanks for any help or advice. You can compare stars like this But it is better to do them with integer. AskQuestion class I have entered the following:
pressed Public Zero Answer 1 (see footage) {intent to myIntent = new intent (AskQuestion .this, CheckQuestion.class); MyIntent.putExtra ("Answer", 1); // Ask alternate criteria Question.this.startActivity (myIntent); } Public Zero Answer 2 Pressed (see footage) {intent to myIntent = new intent (AskQuestion.this, CheckQuestion.class); MyIntent.putExtra ("Answer", 2); // Ask alternate criteria Question.this.startActivity (myIntent); } Press Public Zero Answer 3 (see footage) {intent to myIntent = new intent (AskQuestion.this, CheckQuestion.class); MyIntent.putExtra ("Answer", 3); // Ask alternate criteria Question.this.startActivity (myIntent); } Press Public Zero Answer 4 (see footage) {intent to myIntent = new intent (AskQuestion.this, CheckQuestion.class); MyIntent.putExtra ("Answer", 4); // Ask alternate criteria Question.this.startActivity (myIntent);
checkquestion class
create a protected zeros (bundle saved instenestate) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_check_question); Intent = getIntent (); Intent.getStringExtra ("Answer");
correct answer , to check that I have the Res / values folder But I am struggling to do this work.
if ( Intent.getStringExtra ("Answer"). Equal (getResources (). GetString (R.string.answerstring)) {Toast. Maketext ("the answer is correct"). Show (); }
No comments:
Post a Comment