Saturday, 15 March 2014

How do I compare the data received by new activities in java and xml global strings? (Android) -


I am writing a multi-choice quiz using the Eclipse for Android with 4 buttons for possible answers.

In the 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);   

It should send a string called Answer which declares which button was pressed - is it really happening? I have the following code in the checkquestion class

  create a protected zeros (bundle saved instenestate) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_check_question); Intent = getIntent (); Intent.getStringExtra ("Answer");   

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 correct answer , to check that I have the Res / values ​​folder But I am struggling to do this work.

Thanks for any help or advice.

You can compare stars like this

  if ( Intent.getStringExtra ("Answer"). Equal (getResources (). GetString (R.string.answerstring)) {Toast. Maketext ("the answer is correct"). Show (); }   

But it is better to do them with integer.

No comments:

Post a Comment