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 8273395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:28:52+00:00 2026-06-08T07:28:52+00:00

Im doing a multiple choice apps with 4 choices. How to prompt the user

  • 0

Im doing a multiple choice apps with 4 choices. How to prompt the user of the correct answer if he pressed the incorrect answer (at the same time).Here is a sample of the code.

        //Question/Answer options listener
        optionOne.setOnClickListener(this);     //On First Option selection
        optionTwo.setOnClickListener(this);     //On Second Option selection
        optionThree.setOnClickListener(this);   //On Third Option selection
        optionFour.setOnClickListener(this);    //On Forth Option selection

        skip.setOnClickListener(this);          //On Question Skip      
        pause.setOnClickListener(this);         //On Game Pause
        end.setOnClickListener(this);           //On Game End

    }

    public void onClick(View v) {
        if(v.getId() == optionOne.getId()){
            onOptionSelected(optionOne.getText().toString());
        }else if(v.getId() == optionTwo.getId()){
            onOptionSelected(optionTwo.getText().toString());
        }else if(v.getId() == optionThree.getId()){
            onOptionSelected(optionThree.getText().toString());
        }else if(v.getId() == optionFour.getId()){
            onOptionSelected(optionFour.getText().toString());
        }else if(v.getId() == pause.getId()){   //True when Game is Paused 

    //When an option of a question is selected
    private void onOptionSelected(String option){
        if(!isGamePaused && !isGameEnded) { //true when game is being played
            ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
            if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
                correct += 1;
                remainingTime = mySecondsPassed;
                totalPoints += remainingTime * pointsPerRemainingSecond; 
                totalPoints += pointsPerCorrectAnswer;
            }
            else{
                incorrect += 1;
                totalPoints -= pointsPerWrongAnswer;
            }

I need to insert something on this portion to show the correct answer.

else{
    incorrect += 1;
    totalPoints -= pointsPerWrongAnswer;
    selectedOptionTxt.setBackgroundColor(Color.RED); 

Here is my .plist
<question>
<key>Question</key>
<string>What is the ....</string>
<key>Options</key>
<array>
<string>option 1</string>
<string>option 2</string>
<string>option 3</string>
<string>option 4</string>
</array>
<key>Answer</key>
<integer>2</integer>
 </question>

Here is the other code

public ATriviaQuestion(){
    isThisQuestionAsked = false;
    answer = -1;
    answered = "";
}

public String GetQuestion()
{ return this.question; }

public void SetQuestion(String _question)
{ this.question=_question; }

public ArrayList<String> GetOptions()
{ return this.options; }

public void SetOptions(ArrayList<String> _options)
{ this.options = _options; }

public int GetAnswer()
{ return this.answer; }

public void SetAnswer(int _answer)
{ this.answer = _answer; }
  • 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-08T07:28:53+00:00Added an answer on June 8, 2026 at 7:28 am

    The easiest way that I can see is to alter your onOptionSelected method to take the TextView as a parameter instead of just the string, you’ll still be able to pull the string out in the same manner inside the method as you do outside of it now. And you’ll have the reference that you need to change the background color.

    //When an option of a question is selected
    private void onOptionSelected(TextView selectedOptionTxt){
    String option = selectedOptionTxt.getText().toString();
    
    if(!isGamePaused && !isGameEnded) { //true when game is being played
        ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
        if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
            correct += 1;
            remainingTime = mySecondsPassed;
            totalPoints += remainingTime * pointsPerRemainingSecond; 
            totalPoints += pointsPerCorrectAnswer;  
            selectedOptionTxt.setBackgroundColor(Color.GREEN);
        }
        else{
            incorrect += 1;
            totalPoints -= pointsPerWrongAnswer;
            selectedOptionTxt.setBackgroundColor(Color.RED);
    

    and then change where you are calling this method to pass the entire TextView instead of just the strings. like this:

    onOptionSelected(optionOne);
    

    note that you’ll need to do this for each of the four, not just the one that I’ve shown here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm using /usr/bin/time to measure my program, and I'm doing multiple runs of
I am asking the user 10 multiple choice questions once the questions are answered
I am doing listview with multiple choice,(this listview is not a customized) and more
I am doing an application on a Multiple Choice Question (MCQ) where I have
Currently i have multiple select tags that have almost the same option choices, what
The problem is that when I try doing multiple animations they all happen the
I have a primary key set up to auto increment. I am doing multiple
How can I have multiple buttons and multiple listeners doing various operations in java
I'm doing a table import using a multiple INSERT (INSERT INTO ... VALUES (1),
i am doing a project that will have multiple channels for clients chatting. Each

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.