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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:12:01+00:00 2026-05-29T23:12:01+00:00

I’m coding a chess board. For the layout, I include several merged layouts. I

  • 0

I’m coding a chess board. For the layout, I include several “merged” layouts. I simply would like to access to the “merged” components from the Activity code, in order to change some of their properties (imageView background_color, imageView image path …).

Edit : for example, I want to pass a row id (R.id.row_1), and initialize all components from this row id, with a for loop : the 8 cells are given each a different background color.

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initializeComponents(R.id.row_2);
    }

 public initializeComponents(int id){
       /* inflates the given layout child components
        * and set their properties
        */
 }

Here is my main.xml

<?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/board"/>
</LinearLayout>

Here is my board.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
<include android:id="@+id/row_8" layout="@layout/board_line"/>
<include android:id="@+id/row_7" layout="@layout/board_line"/>
<include android:id="@+id/row_6" layout="@layout/board_line"/>
<include android:id="@+id/row_5" layout="@layout/board_line"/>
<include android:id="@+id/row_4" layout="@layout/board_line"/>
<include android:id="@+id/row_3" layout="@layout/board_line"/>
<include android:id="@+id/row_2" layout="@layout/board_line"/>
<include android:id="@+id/row_1" layout="@layout/board_line"/>

</TableLayout>

Here my board_line.xml:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<TableRow 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>
<ImageView
        android:id="@+id/a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/c"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/d"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/e"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/f"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/g"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
    <ImageView 
        android:id="@+id/h"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/cell_dimension"
        android:minHeight="@dimen/cell_dimension"
        android:maxWidth="@dimen/cell_dimension"
        android:maxHeight="@dimen/cell_dimension"
    />
</TableRow>

Thanks in advance for helps.

  • 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-29T23:12:02+00:00Added an answer on May 29, 2026 at 11:12 pm

    You can use LayoutInflater (or create Views completely programmatically) and combine all those to your needs. The following example should create some random colored 5×5 board. Since setting LayoutParams in code is ugly I would set them in xml and Inflate the layout.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.main, null);
        TableLayout tl = (TableLayout) ll.findViewById(R.id.tableLayout);
        for (int j = 0; j < 5; j++) {
            TableRow tr = (TableRow) inflater.inflate(R.layout.table_row, null);
            for (int i = 0; i < 5; i++) {
                ImageView iv = (ImageView) inflater.inflate(R.layout.image_view, null);
                iv.setBackgroundColor(new Random().nextInt());
                tr.addView(iv);
            }
            tl.addView(tr);
        }
        setContentView(ll);
    }
    

    main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TableLayout
            android:id="@+id/tableLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </TableLayout>
    </LinearLayout>
    

    table_row.xml

    <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>
    

    image_view.xml

    just one of those you defined in board_line.xml:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.