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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:22:33+00:00 2026-06-09T12:22:33+00:00

What is the best way to insert a layout inside another layout at runtime.

  • 0

What is the best way to insert a layout inside another layout at runtime. Specifically I have a FrameLayout that contains a ListView. This is defined in one mainlayout.xml file, and I have another layout file defining the header in header.xml.

1) How do I include the headerlayout.xml defined layout inside the definition of mainlayout.xml.(static case) ie without copying everything inside but referencing the other definition.

2) How could I dynamically add header layout into specific spot in mainlayout.xml at runtime?
I know about inflating and all that, just not sure how to attach it to the spot where I want it in the mainlayout. Since I am not including whole definition in mainlayout.xml how to I have a placeholder there and set it dynamically in the right spot after inflation. (dynamic case).

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

    Static case. Inside your mainlayout.xml:

    <include layout="@layout/header" id="@+id/header" />
    

    Another solution which ca be both static and dynamic is using ViewStub

    <ViewStub android:id="@+id/stub"
              android:inflatedId="@+id/subTree"
              android:layout="@layout/mySubTree"
              android:layout_width="120dip"
              android:layout_height="40dip" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The best way of describing this is I have a table of people with
Best way to describe this is explain the situation. Imagine I have a factory
Best way to 'insert' a page in a TPageControl if i already have many
What would be the best way to insert XML data (that I get from
What's the best way to insert an element into a page's HEAD directly before
does anyone know the best way to insert a column in a datatable at
I am wondering what's the best way to insert customization hooks into my application.
The best way I think to explain this is to tell you what my
The best way to explain my problem is by a example. I have a
the best way to explain is with example so: this is the model public

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.