Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:14:02+00:00 2026-06-10T19:14:02+00:00

Whenever I click on the button, it should change the score if the answer

  • 0

Whenever I click on the button, it should change the score if the answer is correct. However, when i click on next, it does not change the score. it just shows its default which is 0. Everything is okay except for the score.

 public class QuizActivity extends Activity {
    DBAdapter db = new DBAdapter(this);
    private TextView tvQuestion;
    private Cursor c;
    private Cursor cur;
    private RadioGroup radioGroup;
    private RadioButton rb0,rb1,rb2;
    private Button nextButton;
    private int i =1;
    private int questNo=0;
    private RadioButton radioButton;
    private int score=0;
    private String correctAnswer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quizactivity);


    displayQuestion();
    nextButton = (Button) findViewById(R.id.nextButton);
    nextButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            getselectedAnswer();
            checkAnswer();

        if(i < 10){
                i=i+1;


                radioGroup.clearCheck();
                displayQuestion();

                }else{
                Intent i = new Intent(QuizActivity.this, Results.class);
                startActivity(i);
                }
        }
        });
}
        public void checkAnswer() {
        Cursor mCursor = db.getCorrectAnswersforComparison(i);
        String correctAns = mCursor.getString(mCursor.getColumnIndex(DBAdapter.KEY_CORRECTANSWERS));
        if(getselectedAnswer()==correctAns){
            score = score+1;

        }else{
            score = score+0;
        }

        }

private String getselectedAnswer() {    
    if (rb1.isChecked()){
        return rb1.getText().toString();
    }
    if (rb2.isChecked()){
        return rb2.getText().toString();
    }   
    if (rb0.isChecked()){
        return rb0.getText().toString();
    }
    else
        return null;


}
public void displayQuestion(){
    db.open();
    TextView scoretv = (TextView) findViewById(R.id.scoretv);
    scoretv.setText(""+score);
    c = db.getQuiz_Content(i);
    cur = db.getAnswers(i);
    tvQuestion = (TextView) findViewById(R.id.textViewQuestionQA);
    tvQuestion.setText(c.getString(0));
    radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
    String correctAnswer = cur.getString(cur.getColumnIndex(DBAdapter.KEY_CORRECTANSWERS));
    String option1 = cur.getString(cur.getColumnIndex(DBAdapter.KEY_OPTION1));
    String option2 = cur.getString(cur.getColumnIndex(DBAdapter.KEY_OPTION2));
    rb0 = (RadioButton) findViewById(R.id.radio0);
    rb1 = (RadioButton) findViewById(R.id.radio1);
    rb2 = (RadioButton) findViewById(R.id.radio2);
    List<String> answers = new ArrayList<String>();
    answers.add(correctAnswer);
    answers.add(option1);
    answers.add(option2);
    Collections.shuffle(answers);
    rb0.setText(answers.get(0));
    rb1.setText(answers.get(1));
    rb2.setText(answers.get(2));

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:14:03+00:00Added an answer on June 10, 2026 at 7:14 pm

    Your problem is here:

    if(getselectedAnswer()==correctAns)
    

    String comparison on Java doesn’t work with the usual equality operator == (this checks if they are the same instance, not whether the strings contain the same characters). Instead, use the string method .equals:

    if(getSelectedAnswer().equals(correctAns))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I click the button 1 , the application crashes(force closes). I am not
I have an application with many views. Whenever I click the next button on
So whenever I click the button on the startup page, it gives me a
I currently have a delayed task that runs whenever I click a button. Clicking
I am customizing the ribbon toolbar and adding a button to it.Whenever I click
Is there ASP button that won't submit post form data. Whenever I click an
i want to change the incremental for hour and minute, by whenever click on
I get a run-time error NullPointerException whenever I try to click the options button
I want to show up an ASPxPopupControl whenever an user click a button. But
Also, right now whenever I click the 'X button on top right, the dialog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.