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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:26:17+00:00 2026-05-28T17:26:17+00:00

I have a main.xml file describing the layout of my main activity: <?xml version=1.0

  • 0

I have a main.xml file describing the layout of my main activity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />

</LinearLayout>

and its included layout xml file (mylayout.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello world" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

I just want to include “mylayout” in my main layout 5 times, but instead of seeing “hello world” 5 times, I want the TextView to contain custom text.

Is there any way to do this by setting some attribute on the include element to override the child TextView’s text? What would be the best approach to take to accomplish this?

  • 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-28T17:26:18+00:00Added an answer on May 28, 2026 at 5:26 pm

    No, there is no way to pass parameters to the included layout other than the layout params using the <include> directive.

    You can inflate the layout programatically and add them to your view. Add an id to the container in your main layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" />
    

    Then in your Activity:

    ViewGroup container = (ViewGroup)findViewById(R.id.container);
    for (int i = 0; i < 6; i++) {
        View myLayout = getLayoutInflater.inflate(R.layout.mylayout, null);
        TextView tv = myLayout.findViewById(R.id.textView);
        tv.setText("my layout " + i);
        container.addView(myLayout); // you can pass extra layout params here too
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following main.xml file with a LinearLayout <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have this main.xml file: <?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:background=@drawable/background
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
I have a question about Android. Assume we have our main xml layout file,
i am new to android.i have one single activity with main.xml file. Now, i
I have a custom view that I declare in 'main' XML File: <com.app.DrawView android:id=@+id/my_view
I do have a \res\layout\main.xml file. Yet, this: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
i'm developing android in eclipse. i have a main.xml file which has a graphical
I have an ImageView in my main.xml file: <ImageView android:id=@+id/pageImage android:layout_width=270dp android:layout_height=45dp android:layout_alignParentLeft=true android:layout_alignParentTop=true
i have in my android main.xml file as the following.. when i run it

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.