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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:11:19+00:00 2026-05-27T10:11:19+00:00

I have two layouts xml and can’t get the second layout to work correctly.

  • 0

I have two layouts xml and can’t get the second layout to work correctly.
A EditText placed on the second layout doesn’t work as expected. It doesn’t accept characters.

What am i missing here?
Should i use startActivity() instead?

Main.java

public class Main extends Activity implements View.OnClickListener {

    EditText box1, box2;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        showXml1();
    }

    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            String box11 = box1.getText().toString();
            Toast.makeText(this, box11,Toast.LENGTH_SHORT).show();
            showXml2();
            break;
        case R.id.button2:
            String box22 = box2.getText().toString();
            Toast.makeText(this, box22,Toast.LENGTH_SHORT).show();
            showXml1();
            break;
        }
    }

    public void showXml2() {
        setContentView(R.layout.main2);
        box2 = (EditText) findViewById(R.id.editText2);
    }
    public void showXml1() {
        setContentView(R.layout.main);
        box1 = (EditText) findViewById(R.id.editText1);
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Main1" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" 
        android:onClick="onClick"
        />

</LinearLayout>

mail2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Main2" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2" 
        android:onClick="onClick"
        />
</LinearLayout>
  • 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-27T10:11:20+00:00Added an answer on May 27, 2026 at 10:11 am

    Use a meta layout xml file with a structure similar to this one:

    meta_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <ViewFlipper
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
          android:id="@+id/root">
        <include
          layout="@layout/main" />
        <include
           layout="@layout/main2" />
    </ViewFlipper>
    

    And then main.java:

    public class Main extends Activity implements View.OnClickListener {
    
        EditText box1, box2;
        ViewFlipper root;
    
        @Override
        public void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            setContentView(R.layout.meta_main);
            box1 = (EditText) findViewById(R.id.editText1);
            box2 = (EditText) findViewById(R.id.editText2);
            root = (ViewFlipper) findViewById(R.id.root);
        }
    
        public void onClick(View v) {
            EditText editText = null;
            switch (v.getId()) {
                case R.id.button1:
                    editText = box1;
                    root.showNext();
                break;
                case R.id.button2:
                    editText = box2;
                    root.showPrevious();
                break;
            }
            if(editText != null) {
                Toast.makeText(this, editText.getText(), Toast.LENGTH_SHORT).show();
            }
        }
    }
    

    Hope it helps 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two layouts in the same xml file(top layout and bottom bottom layout).
Question 1: I have some XML-based layouts which work fine on phones. But when
I have been trying to get it to work using this thread but can't
I have a layout where I placed a TimePicker and two buttons for select
I have some NSViews that I'm putting in one of two layouts depending on
I have two libraries and a single application assembly project layout and I'm wondering
I have two panels: main_panel child_panel The main_panel layout is set using: main_panel.setLayout(flowlayout) I
Here is the scenario: I have two asp pages. a.aspx is layout and b.aspx
I have the age-old problem of a div wrapping a two-column layout. My sidebar
I have a JFrame with null layout and two one character JLabels on the

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.