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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:50:21+00:00 2026-06-10T20:50:21+00:00

I have a question about Android. Assume we have our main xml layout file,

  • 0

I have a question about Android.
Assume we have our main xml layout file, and defining there a place holder by using (for example) a FrameLayout. Also assume we have 2 other xml layout files displaying any content.
So what I want to do is inject dynamically and programmtically one of the two layouts into the place holder. I know there exists the concept of Activitis, Fragments, ViewFlipper etc. But I find it comfortable to do things like this:

public class MainActivity extends Activity {

private FrameLayout placeHolder;
private View view1;
private View view2;


private RelativeLayout canvasPlaceHolder;
private PuzzleCanvas canvas;
private TextView infoLabel;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init gui
    setContentView(R.layout.activity_main);

    // Load layouts from xml
    LayoutInflater factory = getLayoutInflater();
    view1 = factory.inflate(R.layout.view1, null);
    view2 = factory.inflate(R.layout.view2, null);

}
}

with for example a Button on screen that does something like this:

@Override
public void onClick(View v) {
    placeHolder.removeView(view1);
    placeHolder.addView(view2);
}

For example to show a loadingAnimation (view2) instead of the normal content (view1) and so I can define both views comfortable and independent in xml.

Is the use of LayoutInflater commendable? What about the performance and memory management? What do you think about this? Is that a common way in Android?

  • 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-10T20:50:23+00:00Added an answer on June 10, 2026 at 8:50 pm

    Use ‘include ‘ tag on the xml’s frame layout to include both your xml’s in the main xml. All you have to do is switch their ‘ VISIBILITY’ through java according to ur app logic.
    eg: on a listener, set :

    public void onClick(View v) {          
        innerView1.setVisibilty(View.INVISIBLE); 
        innerView2. setVisibilty(View.VISIBLE);  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about Android Market/Google Play license model for paid applications. First
I have a comprehension question about Android Services. I have a Service that performs
I have a question about making a drawing app for Android. What is the
Possible Duplicate: Detect multitouch with Ontouch listener Android I have a question about detecting
I have a quick question about the accelerometer in Android devices. Is it always
I have a question about postDelayed. The android docs say that it adds the
I have a question about working with time in java, more specificly in Android.
I have a very simple question about menu control in Android. I'm writing a
I have a question about parcelable class (android). Until now, I have passed a
I have a question about rotating the Android device. My code logs a static

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.