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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:14:52+00:00 2026-05-27T10:14:52+00:00

I have 2 layout xml files: highlights.xml and highlights_cell.xml. Here is a simplified version

  • 0

I have 2 layout xml files: “highlights.xml” and “highlights_cell.xml”.

Here is a simplified version of each. I’ve removed the width/height/etc and just kept the important attributes…

highlights.xml

<LinearLayout>
  <uk.co.jasonfry.android.tools.ui.SwipeView android:id="@+id/swipe_view" />
  <uk.co.jasonfry.android.tools.ui.PageControl android:id="@+id/page_control" />
</LinearLayout>

highlights_cell.xml

<LinearLayout android:orientation="vertical">
  <LinearLayout android:id="@+id/linear_layout1" android:orientation="horizontal">
    <ImageView android:id="@+id/logo" />
    <LinearLayout android:id="@+id/linear_layout2" android:orientation="vertical">
      <TextView android:id="@+id/title" />
      <TextView android:id="@+id/subtitle" />
    </LinearLayout>
  </LinearLayout>

  <ScrollView android:id="@+id/scroll_view">
    <TextView android:id="@+id/description" />
  </ScrollView>
</LinearLayout>

The idea is that I want to add several “highlights_cell” to “highlights” through a loop.

I’ve thrown together some test code as follows but, as it’s not working, I suspect that I’m not adding the cell layouts correctly, or perhaps I shouldn’t be using “inflater”…

/** Declare shared variables */
SwipeView mSwipeView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){

    //Initialise layout and variables
    super.onCreate(savedInstanceState);
    setContentView(R.layout.highlights);

    //Setup controls
    mSwipeView = (SwipeView) findViewById(R.id.swipe_view);

    LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);

    //Loop through collection and add views
    for(int i=0; i<7;i++)
    {
        //Create the itemView to use layout xml for each cell  
        View itemView = inflater.inflate(R.layout.highlights_cell, null);

        //Set values within cell
        TextView title = (TextView) itemView.findViewById(R.id.title);
        title.setText("HELLO WORLD_" + i);

        //add the itemView to main view
        mSwipeView.addView(itemView);
    }
}

Is this the correct way to add layouts dynamically to a parent layout?
Thanks!

  • 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-27T10:14:53+00:00Added an answer on May 27, 2026 at 10:14 am

    It looks good except for a few things.

    Because you are adding views to your custom ViewGroup, you will have to be sure that it correctly lays out and displays its children.

    Also, when you add a View to a ViewGroup, you specify the LayoutParams that views can have in that ViewGroup.

    Some more info about creating a custom ViewGroup

    • http://about-android.blogspot.com/2010/05/create-dynamic-view-group.html
    • custom ViewGroup example?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just recently, my Android XML files which define my layout and etc have stopped
I have the following XML layout for a ListActivity. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have the following layout defined for one of my Activities: <?xml version=1.0 encoding=utf-8?>
I have a linear layout with this form <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical
In my android application, I have layout xml files in: layout/ , layout-lan and
I have a basic Android question here: I have a main.xml layout that loads
I have two main.xml files in layout-land and layout-port folders and when the orientation
I have developed an application and created the xml files in different layout :
I have a general question regarding Android's separation of layouts into layout.xml files: My
In my foo_layout.xml file I have a subclassed RelativeLayout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android

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.