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

  • SEARCH
  • Home
  • 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 7798305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:58:04+00:00 2026-06-01T23:58:04+00:00

I am developing an app that is a question’s game. I managed to show

  • 0

I am developing an app that is a question’s game. I managed to show the answers to each question to a different button each time but i am having trouble to check the right answer. My approach is: I created an extra column to the database where i indicate the column where the right answer is(1,2,3 or 4). I use this code for showing the answers in different buttons.

cur = dbHelper.getRandomQuestion();
    String corrans = cur.getString(cur.getColumnIndex("CorrectAnswer"));
    a = Integer.parseInt(corrans);
    String question = cur.getString(cur.getColumnIndex("QUESTIONS"));
    String answer0 = cur.getString(cur.getColumnIndex("ANSWER1"));
    String answer1 = cur.getString(cur.getColumnIndex("ANSWER2"));
    String answer2 = cur.getString(cur.getColumnIndex("ANSWER3"));
    String answer3 = cur.getString(cur.getColumnIndex("ANSWER4"));
    txtQuest.setText(question);

    ArrayList<String> lstAnswers = new ArrayList<String>();
    lstAnswers.add(answer0);
    lstAnswers.add(answer1);
    lstAnswers.add(answer2);
    lstAnswers.add(answer3);

     score.setText("Your score is " + b +","+ a);

    Random random = new Random();

    int[] textViews = new int[] { R.id.button1, R.id.button2, R.id.button3, R.id.button4 };
    int textViewIndex = 0;

    while (lstAnswers.size() > 0)   {
    int index = random.nextInt(lstAnswers.size());
    if(a == index){ b = index;}
    else{}
    String randomAnswer = lstAnswers.remove(index);
    ((TextView)findViewById(textViews[textViewIndex])).setText(randomAnswer);
    ++textViewIndex;
                                    }

To each button call to compare the values of a and b and then act accordingly. But it doesnt seem to work. I understand why but i cannot figure it out. Any help appeciated.

  • 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-01T23:58:06+00:00Added an answer on June 1, 2026 at 11:58 pm

    use Collections.shuffle(list) to shuffle your answer array and then display the answer
    Set a tag as “right” to your button where anwer is correct and later compare the the tagvalue and disply right or wrong

    EDIT: below thing is just an outline

     Here im displaying answers in buttons....
    
        List<Integer> intList = new ArrayList<Integer>(Arrays.asList(0,1,2,3));
            Collections.shuffle(intList);
    
           Log.d("ERR","List after shuffling: " + intList);  
           // below answers will be assiagned randomly to buttons...
            btn_cmpTagline[intList.get(0)].setText(answr1);
            btn_cmpTagline[intList.get(0)].setTag("right");
            btn_cmpTagline[intList.get(1)].setText(answr2);
            btn_cmpTagline[intList.get(1)].setTag("wrong");
            btn_cmpTagline[intList.get(2)].setText(answr3);
            btn_cmpTagline[intList.get(2)].setTag("wrong");
            btn_cmpTagline[intList.get(3)].setText(answr4);
            btn_cmpTagline[intList.get(3)].setTag("wrong");
    

    //On Click

       @Override
        public void onClick(View v) {
            switch(v.getId()){
            case R.id.btn_tag1:
                Log.d("ERR", v.getTag().toString());
                if(v.getTag().toString().equalsIgnoreCase("right")){
                    //this button has right answer .. do anything 
                }
    
                break;
            case R.id.btn_tag2:
                Log.d("ERR", v.getTag().toString());
                if(v.getTag().toString().equalsIgnoreCase("right")){
                    //this button has right answer .. do anything 
                }
    
                break;
            case R.id.btn_tag3:
                Log.d("ERR", v.getTag().toString());
                if(v.getTag().toString().equalsIgnoreCase("right")){
                    //this button has right answer .. do anything 
                }
    
                        --
                        --
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A new question about android and services. Currently I'm developing a App that should
this is my first ever question. I am developing a iPad app that allows
i am developing app that would receive data from server any time. i have
i am using python for developing Google app engine application. my question is that
In the app that I'm developing, I want to have re-occuring task on each
I'm developing an iPhone app that uses a map and show direction between two
i'm developing an app that make requests to the Musicbrainz webservice. I read in
I'm developing web app that user can save his/her work to server. The data
I'm developing an iPhone app that has a network component. I'm developing the app
I'm developing an app that checks several conditions during an incoming phone call. The

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.