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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:05:33+00:00 2026-05-26T13:05:33+00:00

My app has a list of questions.When the functoion getfirstquestion is called,it randomly choses

  • 0

My app has a list of questions.When the functoion getfirstquestion is called,it randomly choses a question,and after that it randomly puts texts on each of the 4 buttons(one of them is the answer to the question).

Everytime a button is pressed,the function checkanswer verifies if the button text equals with the right answer to the right question.If it does,it removes the current question,and calls the getfirstquestion() function to change the question.

The program runs ok,however nothing happens when I press the correct answer button.Can anyone tell me why,and give me a solution? I’m searching the code since 2 hours ago….

    public class startgame extends Activity implements OnClickListener{

final Random rgenerator = new Random();

List<String> questionss1 = new ArrayList<String>();
String thequestion;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.level1);

    questionss1.add("Who is the actual CEO at Apple?");
    questionss1.add("Who is the actual CEO at Microsoft?");
    questionss1.add("Who is the actual CEO at Google?");
    getfirstquestion();

    Button button1 = (Button)findViewById(R.id.button1);
    button1.setOnClickListener(this);

    Button button2 = (Button)findViewById(R.id.button2);
    button2.setOnClickListener(this);
    Button button3 = (Button)findViewById(R.id.button3);
    button3.setOnClickListener(this);
    Button button4 = (Button)findViewById(R.id.button4);
    button4.setOnClickListener(this);
    }
    }

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()){
    case R.id.button1:  

        Button button1 = (Button)findViewById(R.id.button1);
        checkanswer((String) button1.getText());

    case R.id.button2:
       Button button2 = (Button)findViewById(R.id.button2);
           checkanswer((String) button2.getText());

    case R.id.button3:
        Button button3 = (Button)findViewById(R.id.button2);
    checkanswer((String) button3.getText());

    case R.id.button4:
        Button button4 = (Button)findViewById(R.id.button2);
       checkanswer((String) button4.getText());
    }
}
public int checkanswer(String buttontext) {
    if (thequestion.equals("Who is the actual CEO at Apple?") && buttontext == "Tim Cook"){
        questionss1.remove("Who is the actual CEO at Apple?");
        getfirstquestion();
    }

    if (thequestion.equals("Who is the actual CEO at Microsoft?") && buttontext  == "Steve Ballmer"){
        questionss1.remove("Who is the actual CEO at Microsoft?");
        getfirstquestion();
    }

    if (thequestion.equals("Who is the actual CEO at Google?") && buttontext == "Eric Schmidt"){
        questionss1.remove("Who is the actual CEO at Google?");
        getfirstquestion();
    }
    return 0;
}

public void getfirstquestion(){
    //create the buttons
    Button button1 = (Button)findViewById(R.id.button1);
    Button button2 = (Button)findViewById(R.id.button2);
    Button button3 = (Button)findViewById(R.id.button3);
    Button button4 = (Button)findViewById(R.id.button4);

    thequestion = questionss1.get(rgenerator.nextInt(questionss1.size()));
    TextView question = (TextView)findViewById(R.id.textView1);
    question.setText(thequestion);
    questionss1.remove(thequestion);

    if (thequestion.equals("Who is the actual CEO at Apple?")){
        List<String> questions1res = new ArrayList<String>();
        questions1res.add("Eric Schmidt");
        questions1res.add("Steven Sinofsky");
        questions1res.add("Tim Cook");
        questions1res.add("Steve Ballmer");

        button1.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button1.getText());
        button2.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button2.getText());
        button3.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button3.getText());
        button4.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button4.getText());
    }

    if (thequestion.equals("Who is the actual CEO at Microsoft?")){
        List<String> questions1res = new ArrayList<String>();
        questions1res.add("Eric Schmidt");
        questions1res.add("Steven Sinofsky");
        questions1res.add("Tim Cook");
        questions1res.add("Steve Ballmer");

        button1.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button1.getText());
        button2.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button2.getText());
        button3.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button3.getText());
        button4.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button4.getText());
    }

    if (thequestion.equals("Who is the actual CEO at Google?")){
        List<String> questions1res = new ArrayList<String>();
        questions1res.add("Eric Schmidt");
        questions1res.add("Steven Sinofsky");
        questions1res.add("Tim Cook");
        questions1res.add("Steve Ballmer");

        button1.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button1.getText());
        button2.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button2.getText());
        button3.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button3.getText());
        button4.setText(questions1res.get(rgenerator.nextInt(questions1res.size())));
        questions1res.remove(button4.getText());
    }
}
    }
  • 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-26T13:05:34+00:00Added an answer on May 26, 2026 at 1:05 pm

    button1.setOnClickListener(this);

    This code is used to set an OnClickListener to a button. You need to instantiate an OnClickListener in your class and use that. Passing in (this) will pass in the activity. The button clicks will do nothing in this case.

    Something like this:

    button1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // do your checking here
        }
    };
    

    Try that, let me know how it works.

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

Sidebar

Related Questions

In my Rails 3 app, I have a list of questions. Each question has
I have an app that has a list of items. My customer prefers to
I have a basic iPhone/iPad app which has a ; a. List view &
I'm developing a dynamic data web app. On list.aspx page it has GridViewPager control
My app has an options menu that is available in almost all Activities, which
I'm building a small web app that allows users to list their goals. I
My app is a trivia app that i get questions from the database. There
I have a Flex mobile app that currently contains 2 views View 1 has
I have an app that has a tabBar Controller and a navBar Controller. It
I am in the process of trying to make an app that has most

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.