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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:37:49+00:00 2026-05-27T16:37:49+00:00

Difficult to try and phrase this question, but I will try my best. Basically,

  • 0

Difficult to try and phrase this question, but I will try my best.

Basically, I have an application and I would like to split the code up more. To try and explain this, will give an example of one of my screens.

In my home screen, I have a title, user details, balance, next bill details and usage details. I want to split each of these sections into their own views. So what I have in my main XML file is I have 5 different RelativeLayouts, like this

<RelativeLayout android:orientation="vertical"
    android:layout_below="@+id/title" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:id="@+id/layout1">


</RelativeLayout>

One for each function I want to have on my home screen. And as you can see I also have each layout set below the previous layout, so the order is title, layout1, layout2, layout3, layout4. (The reason I am doing this is, that I want each layout to be interchangable, i.e. I could remove layout2, and order then be title, layout1,layout3,layout4 as I may not need the 2nd layout depending on what is required of the app)

So in my main activity class, I have called each of these layouts.

    layoutTitle = (RelativeLayout) findViewById(R.id.title);
    layout1 = (RelativeLayout) findViewById(R.id.layout1);
    layout2 = (RelativeLayout) findViewById(R.id.layout2);
    layout3 = (RelativeLayout) findViewById(R.id.layout3);
    layout4 = (RelativeLayout) findViewById(R.id.layout4);

Then I use layout inflator like so

View view;
    LayoutInflater inflater = (LayoutInflater) getBaseContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.userdata, null);

to set up the layout for each layout I have defined in my xml file.

What I want to know is, is it possible to inflate another activity rather than an XML file? The reason I ask this is, that each function I said the home screen is made up of, title, user details, balance etc, I have an activity for each of these. Each of these functions has custom functionality that I have designed, such as animation etc. If I simply inflate these xml files, then I can’t access the widgets inside so I can’t set up the functionality from Java which is what I need.

If I was able to inflate another activity, then this would not be a problem, as I would set up the functionality for each function in activity, then just inflate that class.

I hope my question was clear, if not I can expand on any areas you are not sure about.

Would be very grateful for any assistance!!

EDIT: If it is not possible to inflate a class, then is there any other way method you could recommend that could solve my problem?

  • 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-27T16:37:50+00:00Added an answer on May 27, 2026 at 4:37 pm

    I do exactly the same as you.

    I use composition in my Java activities to achieve the sharing of functionalities across my activities. I think of activities as “context”, and not as parts of my page that get replicated. So when I am in a certain context (an activity), I then display layout1, layout2 and layout3 with specific parameters, and specific contents that depends on that activity. On another activity, layout1, 2 or 3 could be different, but they have the same location on my screen all the time.

    I use composition through views: all my activities have a superclass (call it anything you want, something like ActivityWithCustomLayout, which contains all my layout as class members (as ViewGroup). They are protected, so each of the variables layout1, layout2 and layout3 are available to all subclass activities of this superclass.

    And when on a specific activity, I populate each of the layouts on my onCreate method with:

    layout1.addView(...something inflated from an XML that depends on that specific activity...);
    layout2.addView(...same principle...);
    

    So in fact all my XML layouts are “parts” of activities, which I inflate at runtime into views, that I add dynamically to my activity when needed.

    You’re right, these explanations are not easy 🙂


    If you target Android >= Honeycomb (including ICS) then have a look at the Fragment framework, it may be a simpler way to achieve all of that (haven’t had a look at that yet).

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

Sidebar

Related Questions

This will be a bit difficult to explain but I will try my best.
The question is a bit difficult to explain, but I will try. I have
This is difficult for me to put right but let me try. I have
This is such a difficult question to explain online but I shall try my
It's pretty difficult to show code for ASP.NET here, so I will try my
This is a difficult and open-ended question I know, but I thought I'd throw
This question will undoubtedly be difficult to answer and ask in a way that
Its a bit difficult to explain, but i will try. Whenever someone clicks on
Following code will compile but crash at run time: int main() { try {
this may be a little difficult to explain, but I'll try. I'm creating a

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.