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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:00:59+00:00 2026-06-05T08:00:59+00:00

How can I open another layout xml file when I click on a button

  • 0

How can I open another layout xml file when I click on a button in main.xml file?

so if I have main.xml which has a button sying click here and I click it, it opens up second.xml file (layout).

  • 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-05T08:01:01+00:00Added an answer on June 5, 2026 at 8:01 am

    First Create your two layout:

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff"  >
    
        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="This is Activity 1" />
    
           <Button android:text="Next"
            android:id="@+id/Button01"
            android:layout_width="250px"
                android:textSize="18px"
            android:layout_height="55px">
        </Button>    
    
    </LinearLayout>
    

    second.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff"  >
    
        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="This is Activity 2" />
    
           <Button android:text="Previous"
            android:id="@+id/Button02"
            android:layout_width="250px"
                android:textSize="18px"
            android:layout_height="55px">
        </Button>    
    
    </LinearLayout>
    

    Second Add your Activity to the manifest file

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.rr"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".Activity1"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".Activity2"></activity>
        </application>
        <uses-sdk android:minSdkVersion="3" />
    </manifest>
    

    Activity1.java

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class Activity1 extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button next = (Button) findViewById(R.id.Button01);
            next.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent myIntent = new Intent(view.getContext(), Activity2.class);
                    startActivityForResult(myIntent, 0);
                }
    
            });
        }
    }
    

    To switch to Activity2 you have to:

    1. Gets a reference to the button with ID Button01 on the layout using
      (Button) findViewById(R.id.Button01).

    2. Create an OnClick listener for the button.

    3. And the most important part, creates an “Intent” to start another
      Activity. The intent needs two parameters: a context and the name of
      the Activity that we want to start (Activity2.class)

    Activity2.java

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class Activity2 extends Activity {
    
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.second);
    
            Button next = (Button) findViewById(R.id.Button02);
            next.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }
    
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I check to see if a file is already open by another
I've a layout now, which has a add location button. The current layout is
Let's say I have a main form that can open MDI children inside it.
A user can open another tab on a browser and look at the same
Can a data grid in another open form be refreshed by calling a sub
How can maintain a SqlConnection (or using another component) open (connected) always during the
If I can open a connection to an MS Access file in C#, how
I have a form that can open a sub form (with ShowDialog ). I
I have a (JSF 2.0/ Primefaces 2.2RC-SNAPSHOT) app that has <p:layout> I use a
So I have a little problem.I can't find how to save a bitmap file

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.