The question is very abstract, I understand it and the answer is naturally waiting for about the same.

What is the logic of the app on Android, the psychological test? It is clear that you need to use the if else , but what to do next is not entirely clear.

For example, there are three questions, in each question there are two choices of the answer and at the end the result is displayed.

For example, the user pressed the button 1 in the first question, I write if (a==1) then {} , and how best to continue to redirect to another activation using intent or is there a more correct way?

  • In the books of P.Datel "Android for Developers" and B.Hardy "Android. Programming for Professionals" there are full and very detailed examples of the development of a quiz application (actually a test) - several questions, choice of options, summing up, and so on. - pavlofff
  • I am sure that by reading the relevant chapters in the books, you will fully solve all the problems of application logic for tests, and after reading them all, you will learn a lot of extremely useful information to such an extent that you can answer the questions yourself and not ask them. - pavlofff
  • pavlofff thanks be sure to read - Artsait

2 answers 2

If you have a lot of questions, then it’s not necessary to fence a bunch of activities / fragments, you will "devour" a lot of phone resources with this approach. Essentially (as I understood from your condition) you have a question and answer options for it. Make one activity in which there will be a TextView (the question itself), several RadioButton and a Button to go to the next question. When you click on a button, you will record the selected answer in your data model and then override the TextView and RadioButton values.

  • I understand you, thank you - Artsait
 switch (answer) { case someAnswer1: //todo Intent otherActivity = new Intent (OtherActivity.this); break; case someAnswer2: //todo Intent anotherActivity = new Intent (AnotherActivity.this); break; case ..... ..... break; 

Pseudocode, but in general it will look like this. To fence a bunch of if not necessary.

  • Thank! That's what he was going to do - Artsait