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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:01:46+00:00 2026-05-22T18:01:46+00:00

hi i have a layout.xml with 3 buttons linked to separate layouts. i have

  • 0

hi i have a layout.xml with 3 buttons linked to separate layouts.

i have managed to code for 1 button using intent. however, i do not know how to add in the next buttons so that they each go to a separate layout. this is my code.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Activity1 extends Activity implements OnClickListener {
    Button hello1, hello2, hello3;
    /** Called when the activity is first created. */

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            hello1 = (Button)findViewById(R.id.hello1);
            hello2 = (Button)findViewById(R.id.hello2);
                hello3 = (Button)findViewById(R.id.hello3);
            hello1.setOnClickListener(this);
            hello2.setOnClickListener(this);
                hello3.setOnClickListener(this);             
        }

        public void onClick(View src) {
          Intent hello1 = new Intent(this, Hello1Activity.class);
          startActivity(hello1);         
          Intent hello2 = new Intent(this, Hello2Activity.class);
          startActivity(oltp);
              Intent hello3 = new Intent(this, Hello3Activity.class);
          startActivity(oltp);
        }
    }

this does not work at all.. the first button when clicked goes to hello3. if i remove the hello2 and hello3, then hello1 works well. any ideas please.

  • 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-22T18:01:47+00:00Added an answer on May 22, 2026 at 6:01 pm

    You’ve attached the same click-listener to all the three buttons and you are starting all the three activities in the onClick method. The Hello3 activity is the one that is started after Hello2Activity and Hello1Activity and hence it is always launched. To achieve what you are trying to do you should attach a different listener to every button and put the code specific to the button there. Something like:

        hello1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View src){
        Intent hello1 = new Intent(this, Hello1Activity.class);
              startActivity(hello1);  }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

enter code here I have a ListView that have a different Layout XML for
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have the following layout buttons.xml <?xml version=1.0 encoding=UTF-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/buttonsLayout android:layout_width=fill_parent android:layout_height=wrap_content
In my layout xml file I have several buttons like this which share the
My Android app having many buttons. My main.xml layout has three buttons. I know
i have some problems in using the date picker from xml layout. in my
I have implemented one up button and one down button in my layout.xml which
I have 1 ListView and 2 buttons in layout.xml file as shown below: <ListView
I have an xml layout which I use for each row in my listview:
I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added

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.