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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:12:38+00:00 2026-05-28T00:12:38+00:00

I want to pass extra to my NextActivity so that a button in NextActivity

  • 0

I want to pass extra to my NextActivity so that a button in NextActivity can have different intents. I am successful with doing this to view different layouts, but no clue on how to do this on a button.
Heres the code that has a working setContentView switch;

public class ContentViewer extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getIntent().getExtras();
    int chooser = bundle.getInt("Layout");

    switch(chooser) {
    case 0:
        setContentView(R.layout.about);
        break;

    case 1:
        setContentView(R.layout.contact);
        break;

    case 2:
        setContentView(R.layout.contentviewer);
        break;

    case 3:
        setContentView(R.layout.contact);
        break;

    case 4:
        setContentView(R.layout.contact);
        break;

    case 5:
        setContentView(R.layout.contact);
        break;

    case 6:
        setContentView(R.layout.contact);
        break;

    case 7:
        setContentView(R.layout.contact);
        break;

    case 8:
        setContentView(R.layout.contact);
        break;

    case 9:
        setContentView(R.layout.contact);
        break;
    }
}
}

Now, in these layouts, there is a button with the same ID, but i want it to have different Intents based on different cases(like the setContentView above).

UPDATE
Theres MainActivity, it has a listview that passes extra. When an item in the listview is clicked, it will open the NextActivity(like in code). NextActivity has a layout that has a Button. Now, based on which item was clicked on the MainActivity, the Button will have different Intents. For example, if in MainActivity, item 1 was clicked, open NextActivity, override Button to have intent 1. If in MainActivity item 2 was clicked, open NextActivity with override button to have intent 2 INSTEAD of intent 1. Clear enough?

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

    Something like this you may need to be:

     int valueFromBundle = get value from bundle here...; 
    
     Button ipButton = (Button)findViewById(R.id.my_button);
    
     ipButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                   switch(chooser) { 
                    case 0:
                    Intent i = new Intent(fromActivity.class, toActivity.class);
                    startActivity(i);
                    break;
                    case 1:
                    Intent i = new Intent(fromActivity.class, toActivity.class);
                    startActivity(i);
                    break;
                    etc..,
    
    
    
                 }
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML that has an extra element and I want it gone.
I want to pass two values to another activity can I do this with
I want to pass an integer value to a form in .Net so that
I want to pass a variable to he buttonEvent method in the selector. [button
I use in my Ajax.Request my jsp. (Prototype) Somehow I can pass extra parameters
Let's say I want to pass some extra data when assigning an event handler.
I want to create an extra radio button with some choices inside an existing
I have an object that has (among other things) a list of Intents. I
I have this HTML piece of code and I want to display:none on the
I have a web app that has a list of user comments. I want

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.