I'm a homegrown greenhorn coder, trying to develop a quiz app for my son's 1st birthday (to family members, of course, not for him).
Problem I'm facing is making results of a quiz visible - and in order by score.
As user is making progress through this quiz, there are two variables gathered: his name (String whatName) and his score (int currentScore).
How can I put these two in a chart at the end of a final question? Preferably aligned by currentScore from best to worst.
Thank You!
edit: I intended to use custom class:
public class results {
public String endName;
public int endScore;
}
and then implement it in last method, toEndResults.
public class MainActivity extends Activity {
int currentScore = 0;
ArrayList<results> result = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
public void toQuiz (View view) {
EditText name = (EditText) findViewById(R.id.name_set);
String whatName = name.getText().toString();
setContentView(R.layout.question);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
}
public void right1 (View view) {
currentScore++;
toQuestion2();
}
public void wrong1 (View view) {
toQuestion2();
}
public void toQuestion2 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question2);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right2 (View view) {
currentScore++;
toQuestion3();
}
public void wrong2 (View view) {
toQuestion3();
}
public void toQuestion3 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question3);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right3 (View view) {
currentScore++;
toQuestion4();}
public void wrong3 (View view) {
toQuestion4();
}
public void toQuestion4 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question4);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right4 (View view) {
currentScore++;
toQuestion5();
}
public void wrong4 (View view) {
toQuestion5();
}
public void toQuestion5 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question5);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right5 (View view) {
currentScore++;
toQuestion6();
}
public void wrong5 (View view) {
toQuestion6();
}
public void toQuestion6 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question6);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right6 (View view) {
currentScore++;
toQuestion7();
}
public void wrong6 (View view) {
toQuestion7();
}
public void toQuestion7 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question7);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right7 (View view) {
currentScore++;
toQuestion8();
}
public void wrong7 (View view) {
toQuestion8();
}
public void toQuestion8 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question8);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right8 (View view) {
currentScore++;
toQuestion9();
}
public void wrong8 (View view) {
toQuestion9();
}
public void toQuestion9 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question9);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right9 (View view) {
currentScore++;
toQuestion10();
}
public void wrong9 (View view) {
toQuestion10();
}
public void toQuestion10 () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.question10);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
}
public void right10 (View view) {
currentScore++;
toEndResults();
}
public void wrong10 (View view) {
toEndResults();
}
public void toEndResults () {
TextView name = findViewById(R.id.name_quiz);
String whatName = name.getText().toString();
setContentView(R.layout.endResults);
TextView contestant = findViewById(R.id.name_quiz);
contestant.setText(whatName);
display(currentScore);
result.add(0, whatName, currentScore));
}
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.score_quiz);
quantityTextView.setText("" + number);
}
}