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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:47+00:00 2026-05-31T02:34:47+00:00

all I have difficulty in linking the two activities by using two buttons. The

  • 0

all

I have difficulty in linking the two activities by using two buttons. The first button serves to select the item in the array. The second function button to proceed to the next page if the text appears on the first button “string 1”

What should I add in my code

This code in array.xml for button3

<string-array name="myArray"> 
<item>string 1</item> 
<item>string 2</item> 
<item>string 3</item> 
<item>string 4</item> 
<item>string 5</item>

This code in beta.java

private String[] myString; 
private static final Random rgenerator = new Random();

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.next);
    Resources res = getResources();

    myString = res.getStringArray(R.array.myArray); 



    Button btn2;
    btn2 = (Button)findViewById(R.id.button3);
    btn2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            final String q = myString[rgenerator.nextInt(myString.length)];

            ((Button) v).setText(q);



        }

    });

    Button btn3;
    btn3 = (Button)findViewById(R.id.button4);
    btn3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });

}
}

What should I add in button4 to be able to go to the next page if the text in the button3 perform “String 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-05-31T02:34:47+00:00Added an answer on May 31, 2026 at 2:34 am

    First thing use the final keyword before button btn2 like

    final Button btn2;
    

    and use the following code at click of button btn 3

    if(btn2.getText().toString().equals("string 1")){
          Intent intent=new Intent(CurrentActivity.this, NextActivity.class);
     startActivity(intent);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of items that all have start and end dates associated
I have three classes that all have a static function called 'create'. I would
I'm sure we all have received the wonderfully vague Object reference not set to
I have created a bunch of movie clips which all have similar names and
I have a bunch of projects in parallel subdirectories that all have etc/lighttpd.conf files.
I have a MFC dialog with 32 CComboBoxes on it that all have the
I have a database with Points of Interest that all have an address. I
So I have a form with lots of controls that all have a tab
I have some tables. These tables all have one column in common called 'classified_id':
I have 3 similar tables, that would all have the same enum type field.

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.