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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:52:53+00:00 2026-05-27T01:52:53+00:00

I have two buttons in one class and those buttons send you to the

  • 0

I have two buttons in one class and those buttons send you to the same class but depending on what button that was pressed it will show different text/images/buttons.

So right now when a button is pressed it send you to the next class and adds some intets, like this:

button1.setOnClickListener(new View.OnClickListener() {  
            @Override  
              public void onClick(View view) {  
                Bundle bundle1 = new Bundle();  
                bundle1.putInt("top", R.drawable.1);  
                bundle1.putInt("mid", R.drawable.2);  
                bundle1.putInt("bot", R.drawable.3);  
                Intent intet1 = new Intent(curclass.this, nextclass.class);  
                intent1.putExtras(bundle1);  
                startActivity(intent1);

In the next class I have a bundle for each button but I belive I need to set a if/else on them to make sure it only uses one of the bundles because it does not work properly right now.

So how do I make the “if” thing?
I have tried but I don’t know what to put after “if”.
Something like

"if (button1 = pressed)  
(do this)  
else if (button2 = pressed)  
(do this)"

Thanks in advance!

Sorry if I explain like a idoit, might be because I am one and I just started to program.

EDIT: The problem is that I have two bundles in the second activity that looks like this:

Bundle asd = getIntent().getExtras();
    int asdasd = asd.getInt("top");
    im1 = (ImageView) findViewById(R.id.imagetop);
    im1.setImageResource(newimage);
    bu1 = (Button) findViewById(R.id.buttontop);
    bu1.setText("blahblah");

And I have the mid and bot one under that and then i have the second bundle which tells the Ints from button2 what images/texts to show and the problem is that it loads that second bundles stuff even if I press button1, which I suspect is caused by the bundles just being there side by side with anything telling them what to do.

I hope that clears it up 🙂

  • 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-27T01:52:53+00:00Added an answer on May 27, 2026 at 1:52 am

    The good thing of get… method of bundles it that you can define a default.

    Put this wherever you want, maybe you have a class for constants, or where you better fill it to stay. Since it is static, you can access it wherever you want.
    Create “global variables” the uniquely identify your buttons.

    public static final int no_button = -1;
    public static final int button_1 = 1;
    public static final int button_2 = 2; //you are not forced to use -1, 1, 2, just use different numbers
    

    Always in your first activity, after the button is pressed

    button1.setOnClickListener(new View.OnClickListener() {  
                @Override  
                  public void onClick(View view) {  
                    Bundle bundle1 = new Bundle(); 
                    bundle1.putInt("button id", button_1); 
                    bundle1.putInt("top", R.drawable.1);  
                    bundle1.putInt("mid", R.drawable.2);  
                    bundle1.putInt("bot", R.drawable.3);  
                    Intent intet1 = new Intent(curclass.this, nextclass.class);  
                    intent1.putExtras(bundle1);  
                    startActivity(intent1);
    

    or

    button2.setOnClickListener(new View.OnClickListener() {  
                @Override  
                  public void onClick(View view) {  
                    Bundle bundle2 = new Bundle();  
                    bundle2.putInt("button id", button_2);
                    bundle2.putInt("top", R.drawable.1);  
                    bundle2.putInt("mid", R.drawable.2);  
                    bundle2.putInt("bot", R.drawable.3);  
                    Intent intet2 = new Intent(curclass.this, nextclass.class);  
                    intent2.putExtras(bundle1);  
                    startActivity(intent1);
    

    Then in the second activity

    Bundle asd = getIntent().getExtras();
    switch(asd.getInt("button id", -1)){
    case button_1:
        [put here the code you want to execute if button1 was pressed]
    case button_2:
         [put here the code you want to execute if button2 was pressed]
    case no_button:
         [put here the code you want to execute if something else happened]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with two buttons. Depending on which one is clicked a
In Application i have two buttons in which one button is used as a
I have a page with two buttons, one Button opens a popup window with
I have a form that has two buttons on it, one yes, one no,
I have two functions: one that creates a new <textarea> when a button is
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have one view ,view contains two buttons and one gallery. Gallery view pleased
I have two radio buttons next to each other, and even though each one
I have two radio buttons each with a unique ID. When one is clicked,
I am trying to have two submit buttons in my form - one accepts

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.