I have an Array of int that stores the Questions in (ID) mode for this reason it is not of type String. I have another Boolean Array that stores the correct answers.
The original idea is that a for cycle traverses the Array of questions and the counter shows what is in the certain positions by After the TextView the user should press the button true / false to give the value to a variable that will be compared with "Correct answer" so that in the end a Toast will return correct or incorrect as the condition is met with an if / else simple.
I DO NOT ACHIEVE THE TEXVIEW SHOW WHAT IS IN THE "n" POSITION OF THE STICKER ARRAY. HOW CAN I MAKE THE TEXVIEW SHOW EACH OF THE POSITIONS.
QuizActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuizActivity extends Activity {
private Button mTrueButton;
private Button mFalseButton;
private int mostradorPregunta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
//= findViewById(0x7f060029);
//COMIENZA EL ARRAY DE PREGUNTAS
int preguntas [] = new int[3];
preguntas [0] = 0x7f060025;
preguntas [1] = 0x7f060026;
preguntas [2] = 0x7f060027;
preguntas [3] = 0x7f060028;
//COMIENZA ARRAY DE RESPUESTAS
boolean respuestaCorrecta [] = new boolean[3];
respuestaCorrecta [0] = true;
respuestaCorrecta [1] = false;
respuestaCorrecta [2] = false;
respuestaCorrecta [3] = true;
TextView mVisorPregunta = new TextView(this);
mVisorPregunta.setText(mVisorPregunta);
for (mostradorPregunta = 0; mostradorPregunta < preguntas.length; mostradorPregunta++){
mVisorPregunta = mostradorPregunta;
}
mTrueButton = findViewById(0x7f0b005e);
mTrueButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
}
});
mFalseButton = findViewById(0x7f0b005f);
mFalseButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
}
});
}
strings.xml
<resources>
<string name="app_name">GeoQuiz</string>
<string name="question_text">¿LOS GATOS TIENEN DOS OJOS?</string>
<string name="true_button">Cierto</string>
<string name="false_button">Falso</string>
<string name="correct_toast">Correcto!</string>
<string name="incorrect_toast">Incorrecto!</string>
<string name="pregunta1">¿El cielo es azul?</string>
<string name="pregunta2">¿Android es desarrollado por Apple?</string>
<string name="pregunta3">¿Los gatos pueden respirar bajo el agua?</string>
<string name="pregunta4">¿Las aguilas pueden volar?</string>
</resources>
activity_quiz.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/question_text"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button"
android:id="@+id/true_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button"
android:id="@+id/false_button"/>
</LinearLayout>
</LinearLayout>