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

  • Home
  • SEARCH
  • 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 7989507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:46:17+00:00 2026-06-04T12:46:17+00:00

I have one activity and want to display another inside it. Here’s my layout:

  • 0

I have one activity and want to display another inside it. Here’s my layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

  <LinearLayout
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
  </LinearLayout>

</LinearLayout>

How can I display an Activity in inner LinearLayout on button click?

  • 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-04T12:46:19+00:00Added an answer on June 4, 2026 at 12:46 pm

    Use one layout for several activities

    Layout instance is inflated for each activity using a setContentView method, usually in onCreate:

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

    So there’s no problem to use the same XML layout for different activities.

    Display one activity inside another

    You can use a Fragment API to complete the task. See full details in developer’s guide.

    • Declare a layout like that and Android will create fragments for you:

      <?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">
      
          <fragment android:name="com.example.MyFragment"
                  android:id="@+id/my_fragment"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_weight="1" />
      
      </LinearLayout>
      

      Then create a MyFragment class and load it when appropriate.

    • Create fragments yourself. Do not define the Fragment in XML layout:

      <?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:id="@+id/my_parent_layout">
      
      </LinearLayout>
      

      After your parent Activity is created you can add a new Fragment in this way:

      FragmentManager fragmentManager = getFragmentManager()
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      MyFragment fragment = new MyFragment();
      fragmentTransaction.add(R.id.my_parent_layout, fragment);
      fragmentTransaction.commit();
      

      Here MyFragment is defined like this:

      public class MyFragment extends Fragment {
          ...
      }
      

    If you’re targeting below Android 3.0, consider using support package for that.

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

Sidebar

Related Questions

I have the following View setup in one of my Activities: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/photoLayout
I am trying to display ListView . I have created one activity , in
I have implemented onRetainNonConfigurationInstance() on one of my Activity to handle android screen orientation.
I have one Application which has more then 5 Activity I want to know
Here's scenario: I have 2 activities and one service First activity is a landing
I have a design of activities like this I have one main activity and
Within one Activity I have th following piece of code: public void onStartMonitoringToggleClicked(View v)
My one activity seems to have grown quite a bit and I feel like
I have one SubjectTabActivity and i need to show listview on this activity. But
I have an ArrayList of objects in one activity and I need this arrayList

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.