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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:23:32+00:00 2026-06-14T23:23:32+00:00

I’m taking Questions and Answers in String[] .The TextView has questions and RadioButton has

  • 0

My Requirement

I’m taking Questions and Answers in String[].The TextView has questions and RadioButton has corresponding answers. If Start Button is clicked, first set of question and answers is displayed in Linear Layout1. If Next Button is clicked LinearLayout1 is replaced by next set of question with answers and again if Next Buttonis clicked next set of question has to be replaced and vice versa. Help me in writing code for Next Button

Note: Only LinearLayout 1 should be changed when clicking Next Button

code:

TextView tv;
RadioButton rb1, rb2;
Button bStart, bNext;
String question[] = { "Key Lime Pie is upcoming version",
        "Android is Middleware", "Which is latest Android version?" };
String answerA[] = { "True", "False" };
String answerB[] = { "True", "False" };
String answerC[] = { "Android 4.2", "Android 5" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ques);
    tv = (TextView) findViewById(R.id.textView111);
    rb1 = (RadioButton) findViewById(R.id.radioButton1);
    rb2 = (RadioButton) findViewById(R.id.radioButton2);

    bStart = (Button) findViewById(R.id.startExam);
    bNext = (Button) findViewById(R.id.bNext);
    bStart.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            tv.setText(question[0]);
            rb1.setText(answerA[0]);
            rb2.setText(answerA[1]);
        }
    });
    bNext.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            tv.setText(question[1]);
            rb1.setText(answerB[0]);
            rb2.setText(answerB[1]);

        }
    });
}
  • 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-14T23:23:34+00:00Added an answer on June 14, 2026 at 11:23 pm

    This is a logic problem.

    1. Merge all the answers into a multidimensional array.
    2. Keep track of the current question.
    3. Use the tracking variable to get the question title in question.
    4. Use the tracking variable to get the answers in the multidimensional array of answers. This is the first dimension of the array.
    5. You read the answers in that dimension and display them in rb1 and rb2.

    By using what you have there you will have problems extending that code. After all, are you really going to create a new variable for each different set of answers? It does not make any sense. A multidimensional array works.

    However… although you can improve your arrays structure and use an int to keep track of the current displayed question (and thus increment it to get the next question after pressing the bNext), I suggest you try to create more meaningful objects, like a Question class, with relevant members (title, optionA, optionB, whatever…), especially because it looks like you’re using this code to learn how to program a quiz-styled application.

    Then you can create various questions and iterate through then.

    But is that the issue there? No. The problem is keeping track of questions and answers. Use a multidimensional array with a tracking variable.

    // edited: OK, I’m going to suggest something very quick for you:

    static String[] questions = new String[] { "Question 1", "Question 2", "Question 3" };
    static String[][] answers = new String[][] {
            {"Answer 1.a", "Answer 1.b"},
            {"Answer 2.a", "Answer 2.b"},
            {"Answer 3.a", "Answer 3.b"},
        };
    int pos = -1;
    
    void showNextAnswer() {
        pos++;
        tv.setText(questions[pos]);
        rb1.setText(answers[pos][0]);
        rb2.setText(answers[pos][1]);
    }
    
    bStart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showNextAnswer();
        }
    });
    
    bNext.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showNextAnswer();
        }
    });
    

    As you can, both buttons do the same thing, so it’s probably better to only use a next button.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to count the length of a string with PHP. The string

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.