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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:35:12+00:00 2026-05-22T12:35:12+00:00

I am relatively new to android, i need to open a new screen when

  • 0

I am relatively new to android, i need to open a new screen when a button is clicked.
As i checked the posts here they suggest using setContentView() or using an Intent.
In case 2 a new the screen is opened as a new Activity, as i dont want this to happen
could u tell me if i can use LayoutInflater to open a new screen, if so how to do this.

  • 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-22T12:35:13+00:00Added an answer on May 22, 2026 at 12:35 pm

    your question suggests that, there is no need to use LayoutInflater. Check this code:

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basic_layout_1);
        Button button = (Button) findViewById(R.id.basic_layout_1_button);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                setContentView(R.layout.basic_layout_2);
            }
        });
    }
    

    Here is all you need I think. But just in case I’m also posting XML files:

    basic_layout_1.xml code

    <?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="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello world! - Basic layout 1"
        android:textSize="32dip">
    </TextView>
    <Button
        android:id="@+id/basic_layout_1_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Basic layout 1 Button">
    </Button>
    </LinearLayout>
    

    and basic_layout_2.xml code

    <?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="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello world! - Basic layout 2"
        android:textSize="32dip">
    </TextView>
    </LinearLayout>
    

    //EDIT
    What is important, this method of creating a new screen will cause that back button won’t display basic_layout_1 but it’ll exit your app (in example above). If you’d like to display previous screen you should override back button action (but in that case, why not use Intent?)

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

Sidebar

Related Questions

I relatively new to using Eclipse with the Android SDK. Whenever I encounter an
I'm relatively new to java and android, in my android application I need to
I'm relatively new in Android's world and the UI/Thread model is still confusing. Here
I am relatively a new Android developer and I am not able to understand
I'm relatively new to Android programming, and am having a problem with inflation. I'm
I'm still relatively new to Java and Android development, so I'm still unfamiliar with
I am a relatively new Android programmer and I was wondering how you could
Hi I'm relatively new to Android programming but I would be grateful of some
I am relatively new to Android. My experience in testing isn't too deep either.
I am relatively new to android. I have two applications A and B. I

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.