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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:51:11+00:00 2026-05-19T16:51:11+00:00

I have a simple quiz game which is working well but the one problem

  • 0

I have a simple quiz game which is working well but the one problem I am having is that the answer and options to the questions are displayed on buttons but the answer button appears in the same place everytime.

Is there a way to randomise the positioning through the XML interface or would it be better to handle this on the coding side?

Below is the code I am using for the XML and the code I use to bind the data value from SQLite to the buttons. Any advice would be much appreciated.

private void showQuestions(Cursor cursor) {
// Collect String Values from Query
StringBuilder questiontxt = new StringBuilder("");
StringBuilder answertxt1 = new StringBuilder("");
StringBuilder answertxt2 = new StringBuilder("");
StringBuilder answertxt3 = new StringBuilder("");
StringBuilder answertxt4 = new StringBuilder("");

while (cursor.moveToNext()) {
String question = cursor.getString(2);
String answer = cursor.getString(3);
String option1 = cursor.getString(4);
String option2 = cursor.getString(5);
String option3 = cursor.getString(6);
questiontxt.append(question).append("");
answertxt1.append(answer).append("");
answertxt2.append(option1).append("");
answertxt3.append(option2).append("");
answertxt4.append(option3).append("");
}
// Display answer button
TextView answer = (TextView) findViewById(R.id.option1_button);
answer.setText(answertxt1);
//Display question
TextView text = (TextView) findViewById(R.id.text);
text.setText(questiontxt);
TextView optionbutton1 = (TextView) findViewById(R.id.option2_button);
optionbutton1.setText(answertxt2);
TextView optionbutton2 = (TextView) findViewById(R.id.option3_button);
optionbutton2.setText(answertxt3);
TextView optionbutton3 = (TextView) findViewById(R.id.option4_button);
optionbutton3.setText(answertxt4);
}

And the XML

<Button
android:id="@+id/option1_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/option3_button"/>

<Button
android:id="@+id/option2_button"
android:text="@string/option2_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@+id/option4_button"/>

<Button
android:id="@+id/option3_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option3_label"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>

<Button
android:id="@+id/option4_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option4_label"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
  • 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-05-19T16:51:12+00:00Added an answer on May 19, 2026 at 4:51 pm

    Hi I would suggest handle that on the coding side..I doubt I you would be able to chieve this on the xml side!!

        int randomInt = Math.random() * 1000;
    
        TextView answer = (TextView) findViewById(R.id.option1_button);
        answer.setText(answertxt1);
        //Display question
        TextView text = (TextView) findViewById(R.id.text);
        text.setText(questiontxt);
    if(randomInt%3==0){
        TextView optionbutton1 = (TextView) findViewById(R.id.option2_button);
        optionbutton1.setText(answertxt2);
        TextView optionbutton2 = (TextView) findViewById(R.id.option3_button);
        optionbutton2.setText(answertxt3);
        TextView optionbutton3 = (TextView) findViewById(R.id.option4_button);
        optionbutton3.setText(answertxt4);}
    else {TextView optionbutton1 = (TextView) findViewById(R.id.option3_button);
        optionbutton1.setText(answertxt3);
        TextView optionbutton2 = (TextView) findViewById(R.id.option4_button);
        optionbutton2.setText(answertxt4);
        TextView optionbutton3 = (TextView) findViewById(R.id.option2_button);
        optionbutton3.setText(answertxt2);}
    

    you can try various random methods to display in various way!! I hope
    this helps

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

Sidebar

Related Questions

I have simple php validation form that is halfway working. If you leave the
I'm making a simple quiz application which has multiple questions. It has no back
I am developing a simple Quiz Engine similar to that one in the ASP.NET
I'm making a simple quiz database, where a question has an answer and one
I have two tables that pertain to this part of a trivia quiz game:
I have a simple quiz application and I want display a nice timer /
I have simple class with width and height member fields which define number of
I have simple database - one table with 6 collumns. 3 of them i
I have simple win service, that executes few tasks periodically. How should I pass
so i'm writing a simple quiz script: user gets list of questions and has

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.