Note that there are some explanatory texts on larger screens.

plurals
  1. PONot looping through for loop - Java (android)
    primarykey
    data
    text
    <p>The program works and comes up. When I click start on the main menu it brings up a question (textview) and 4 answers (buttons). Text is assigned to the textview and the 4 buttons with the for-loop. It is never looping through after clicking a button. Nothing happens when clicking a button.</p> <p>I have tried putting in a "break" and changing to a while loop and just can't get it working. I think this is a simple fix that I just cannot find.</p> <p>Any other code structure or advice is appreciated and needed!</p> <pre><code>public class QuestionView extends Activity { Quiz quiz = new Quiz(); ArrayList&lt;Question&gt; queries = quiz.getRandom10(); int correctAnswers = 0; int wrongAnswers = 0; int answer = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.questionviewmain); TextView question = (TextView)findViewById(R.id.question); Button answer1 = (Button)findViewById(R.id.answer1); Button answer2 = (Button)findViewById(R.id.answer2); Button answer3 = (Button)findViewById(R.id.answer3); Button answer4 = (Button)findViewById(R.id.answer4); for(int i = 0; i &lt; 10; i++) { question.setText(queries.get(i).getQuery()); answer1.setText(queries.get(i).getA1()); answer2.setText(queries.get(i).getA2()); answer3.setText(queries.get(i).getA3()); answer4.setText(queries.get(i).getA4()); answer = queries.get(i).getCorrectAnswer(); answer1.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if(answer == 0) { correctAnswers++; } else { wrongAnswers++; } } }); answer2.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if(answer == 1) { correctAnswers++; } else { wrongAnswers++; } } }); answer3.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if(answer == 2) { correctAnswers++; } else { wrongAnswers++; } } }); answer4.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if(answer == 3) { correctAnswers++; } else { wrongAnswers++; } } }); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload