- Forum posts: 3
Apr 21, 2017, 10:41:57 PM via Website
Apr 21, 2017 10:41:57 PM via Website
Hello all,
I have a multiple choice quiz with 10 questions. When I go through the quiz and pick the 10 answers when I get to the results it says 6 out of 10 instead of 10 out of 10.
Here are the questions:
package com.example.dan.biblechallenge;
import android.content.Intent;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.List;
public class QuestionActivity extends AppCompatActivity implements View.OnClickListener{
int score = 0;
Button button;
int qid = 0;
Button btnA, btnB, btnC, btnD;
TextView txtQuestion;
List whyQuesList;
QuestionsTable currentWhyQ;
CountDownTimer countDownTimer;
TextView textV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question);
MySQLiteHelper db = new MySQLiteHelper(this);
whyQuesList = db.getAllWhys();
currentWhyQ = whyQuesList.get(qid);
txtQuestion = (TextView) findViewById(R.id.txtViewQuestion);
final TextView myTimer = (TextView) findViewById(R.id.txtViewTimer);
btnA = (Button) findViewById(R.id.btnOptionA);
btnA.setOnClickListener(this);
btnB = (Button) findViewById(R.id.btnOptionB);
btnB.setOnClickListener(this);
btnC = (Button) findViewById(R.id.btnOptionC);
btnC.setOnClickListener(this);
btnD = (Button) findViewById(R.id.btnOptionD);
btnD.setOnClickListener(this);
setWhyQuestionView();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnOptionA:
if (currentWhyQ.getAnswer().equals(btnA.getText())) {
score += 1;
}
if (qid < 10) {
currentWhyQ = whyQuesList.get(qid);
setWhyQuestionView();
} else {
Intent intent = new Intent(QuestionActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
}
break;
case R.id.btnOptionB:
if (currentWhyQ.getAnswer().equals(btnB.getText())) {
score += 1; }
if (qid < 10) {
currentWhyQ = whyQuesList.get(qid);
setWhyQuestionView();
} else {
Intent intent = new Intent(QuestionActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
}
break;
case R.id.btnOptionC:
if (currentWhyQ.getAnswer().equals(btnC.getText())) {
score += 1;
}
if (qid < 10) {
currentWhyQ = whyQuesList.get(qid);
setWhyQuestionView();
} else {
Intent intent = new Intent(QuestionActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
}
break;
case R.id.btnOptionD:
if (currentWhyQ.getAnswer().equals(btnD.getText())) {
score += 1; }
if (qid < 10) {
currentWhyQ = whyQuesList.get(qid);
setWhyQuestionView();
} else {
Intent intent = new Intent(QuestionActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
}
break;
}
}
public void setWhyQuestionView() {
txtQuestion.setText(currentWhyQ.getQuestion());
btnA.setText(currentWhyQ.getMultipleChoiceA());
btnB.setText(currentWhyQ.getMultipleChoiceB());
btnC.setText(currentWhyQ.getMultipleChoiceC());
btnD.setText(currentWhyQ.getMultipleChoiceD());
qid++;
}
}
Here is the results code:
package com.example.dan.biblechallenge;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class ResultActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView t=(TextView)findViewById(R.id.txtViewResult);
Bundle b = getIntent().getExtras();
int value = b.getInt("score");
t.setText("You answered: " + value + " out of 10! ");
addListenerOnButton();
}
public void addListenerOnButton () {
final Context context = this;
button = (Button) findViewById(R.id.btnGo);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, CategoryActivity.class);
startActivity(intent);
}
});
}
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.