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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:52:43+00:00 2026-05-30T00:52:43+00:00

1.first a random number is selected. 2.the random number corresponds to a case (trivia

  • 0

1.first a random number is selected.

2.the random number corresponds to a case (trivia question) in a switch statement.

3.the case has an onClick() for every possible answer.

4.when the correct answer (and it’s corresponding onClick) is selected
I want the dice to roll again and progress the game to the next question.

5.My debug log says tells me the value of this dice rolled. However, I cannot get the view to change for the corresponding case in the switch.

`public class BeginGame extends Activity  {

Random generator = new Random();
private static final String TAG = "MyActivity";

boolean dupe = true;

boolean done = false;
int intitializedQuestionValue = -2;
final int rows = 3;
final int columns = 25; 
final int RIGHT = -2000;
final int WRONG = -1000;
int score = 0;
int num;

//define array of three rows and 25 columns
int[][] questionArray = new int [rows][columns];
int[] questionNumber = new int [25];

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);

    final Button button0 = (Button) findViewById(R.id.button0);
    final Button button1 = (Button) findViewById(R.id.button1);
    final Button button2 = (Button) findViewById(R.id.button2);
    final Button button3 = (Button) findViewById(R.id.button3);
    final TextView text = (TextView) findViewById(R.id.TextView01);

    //initialize "dice"
    for (int i=0; i<25; i++){
        questionNumber[i] = -1;
    }


    for(int i=0; i < columns; i++)
        questionArray[0][i] = intitializedQuestionValue;

    //set all questions to answered WRONG
    for (int i=0; i <columns; i++)
        questionArray[1][i] = WRONG; 

    rollDice();

    loop: while (!done) 

        switch (num) {
        case 0:            

            text.setText("press Virginia0:");

            button0.setText("Alabama");
            button0.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {
                    Toast.makeText(BeginGame.this, "fail", Toast.LENGTH_SHORT).show(); rollDice(); 


                    //questionArray[2][0]= score -2;


                }

            });
            button1.setText("Mississippi");
            button1.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Toast.makeText(BeginGame.this, "fail", Toast.LENGTH_SHORT).show(); rollDice();


                    //questionArray[2][0]= score - 2;

                }
            });


            button2.setText("Philadelphia");
            button2.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {
                    Toast.makeText(BeginGame.this, "fail", Toast.LENGTH_SHORT).show(); rollDice();


                    //questionArray[2][0]= score -2;



                }
            });

            button3.setText("Virginia"); 
            button3.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {
                    Toast.makeText(BeginGame.this, "success", Toast.LENGTH_SHORT).show(); rollDice();


                    //questionArray[1][0]=RIGHT;
                    //questionArray[2][0]= score + 5;



                }
            });


            break loop; 

        case 1:             

            text.setText("press alabama1:");

            button0.setText("Alabama");
            button0.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {
                    Toast.makeText(BeginGame.this, "success", Toast.LENGTH_SHORT).show(); rollDice();




                }
            });

            button1.setText("Mississippi");
            button1.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {


                }
            });

            button2.setText("Philadelphia");
            button2.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {


                }
            });

            button3.setText("Virginia"); 
            button3.setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {


                }
            });


            break loop; 

`

  • 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-30T00:52:44+00:00Added an answer on May 30, 2026 at 12:52 am

    your program won’t work this way. You have to understand more of android.

    The onCreate method is called when an activity is created. ie : when it comes to front. It is executed on the UI thread : a thread that interacts with the user and should never be blocked. So, you are basically blocking the UI thread with your loop (does num ever change by the way ?).

    What you should do is remove your while loop from the onCreate method. Just use it to initialize your activity, maybe data structures like questions and widgets and their listeners.

    And now give more logic to your listeners : when a button is clicked then change your question and refresh the interface so that the new questions display. Do that until there is no more question to ask.

    Do never block the UI Thread, make it free so users can use your app.

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

Sidebar

Related Questions

George Marsaglia has written an excellent random number generator that is extremely fast, simple,
I m trying to make a random number generator in android. My code has
I am trying to implement the random number generator defined in this answer .
This is the first time I'm trying random numbers with C (I miss C#).
A random class definition: class ABC: x = 6 Setting some values, first for
First let me say that I really feel directionless on this question. I am
I am currently working on a random number generator script that will generate three
I have an unsigned int storing a random number. I need to use this
i am trying to generate random number for my mental math quiz game. But
I know I can use a quasi-random number generation function/variable called Rnd. However, I've

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.