I'm confused on how can I open another activity after finishing the array count and how can i pass the value of score.
I'm new to android that's why I'm confused, I'm Sorry T_T.
this is my code:
package com.letsgo.finalsjavaandroid;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Quest1 extends AppCompatActivity {
private Superclass qClass = new Superclass();
private TextView txtScores;
private TextView txtQuestionss;
private Button Choices1;
private Button Choicess2;
private Button Choicess3;
private String answers;
private int scoring = 0;
private int questnum = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quest1);
txtScores = (TextView)findViewById(R.id.txtScore);
txtQuestionss = (TextView)findViewById(R.id.txtQuestions);
Choices1 = (Button) findViewById(R.id.btnChoice1);
Choicess2 = (Button)findViewById(R.id.btnChoice2);
Choicess3 = (Button) findViewById(R.id.btnChoice3);
updateQuestions();
Choices1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Choices1.getText()== answers){
scoring = scoring + 1;
updateScore(scoring);
updateQuestions();
Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
updateQuestions();
}
}
});
Choicess2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Choicess2.getText()== answers){
scoring = scoring + 1;
updateScore(scoring);
updateQuestions();
Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
updateQuestions();
}
}
});
Choicess2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Choicess2.getText()== answers){
scoring = scoring + 1;
updateScore(scoring);
updateQuestions();
Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
updateQuestions();
}
}
});
}
private void updateQuestions(){
txtQuestionss.setText(qClass.getQuestions(questnum));
Choices1.setText(qClass.Choice1(questnum));
Choicess2.setText(qClass.Choice2(questnum));
Choicess3.setText(qClass.Choice3(questnum));
answers = qClass.Answers(questnum);
questnum++;
}
private void updateScore(int point){
txtScores.setText(""+ scoring);
}
}
and this is the code for superclass:
public class SuperClass {
private String Quests[] = {
"In the anime series Full Metal Alchemist, what do Alchemists consider the greatest taboo?",
"Who is the protagonist of Boku no hero Academia",
"Who is the sister of byakuya in bleach",
"What's the name of the antagonist who put a hole in goku's body",
"Who is Naruto's father"
};
private String Choices [][] = {
{ "Human Transmutation","Magic","Killing"},
{"Bakugo","Deku","All Might"},
{"Rukia","Orihime","Doraemon"},
{"Cell","Buu","Rize"},
{"Jiraiya","Iruka","Minato"}
};
private String CorrectAnswers [] =
{"Human Transmutation","Deku","Rukia","Cell","Minato"};
public String getQuestions(int a ){
String question = Quests[a];
return question;
}
public String Choice1(int a){
String Choice0 = Choices[a][0];
return Choice0;
}
public String Choice2(int a){
String Choice01 = Choices[a][1];
return Choice01;
}
public String Choice3(int a){
String Choice02 = Choices[a][2];
return Choice02;
}
public String Answers(int a ){
String answer = CorrectAnswers[a];
return answer;
}
}
In advance, Thanks for helping me UwU Sorry for adding unnecessary words it's just my post is mostly code that's why i need to post some.