Hi i am Beginner in Android and Java..I am currently building Android quiz game. The application should display 6 questions with 4 answers, if the player's answer is correct then player will move to another question and score 5 points, feedback to the player should be provided as well (im planning to use Toast for this one). In the end, player will get to the final screen to see the total score and correct answer.. here is what i have done so far:
public class play extends Activity implements OnClickListener {
private int totalcorrectanswers;
private int correctanswers;
private Random random;
private TextView questiontextview;
private int score;
private int finalscore;
Button answer1,answer2,answer3,answer4;
Button AnswerButtons [] = {answer1,answer2,answer3,answer4};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
View AnswerButton1 = findViewById(R.id.answerbutton1);
AnswerButton1.setOnClickListener(this);
View AnswerButton2 = findViewById(R.id.answerbutton2);
AnswerButton2.setOnClickListener(this);
View AnswerButton3 = findViewById(R.id.answerbutton3);
AnswerButton3.setOnClickListener(this);
View AnswerButton4 = findViewById(R.id.answerbutton4);
AnswerButton4.setOnClickListener(this);
}
public play() {
}
@Override
public void onClick(View v) {
}
}
and here is the XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity = "center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/scorenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/questions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center" >
<Button
android:id="@+id/answerbutton1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/answerbutton2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/answerbutton3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/answerbutton4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
Now, I am not sure how to display the 6 Questions and 4 answers by using ArrayList?
i have never done quiz/trivia game before..