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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:44+00:00 2026-05-27T21:42:44+00:00

I want to crate custom TableLayout with rows like this: TV is for TextView,

  • 0

I want to crate custom TableLayout with rows like this:

TV is for TextView, i.e. I want to add 11 TextViews to the row:

enter image description here

Each row begins with a title and then I add 5 pairs of TextViews, so that table row is as wide, as screen is.
Here’s my code:

public class FlowTable extends TableLayout {

    private Context context;

    public FlowTable(Context context) {
        super(context);
        this.context = context;
    }

    public FlowTable(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public void addContent(List<ResultItem> data) {

        TableRow tableRow = new TableRow(context);

        LayoutParams params = new LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);

        for (int i = 0; i < data.size(); i++) {

            if (i % 5 == 0) {
                this.addView(tableRow, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

                tableRow = new TableRow(context);
                TextView tvRange = new TextView(context);
                tvRange.setLayoutParams(params);
                tvRange.setText(genRange(i+1));
                tableRow.addView(tvRange);

            }
            TextView tvDistance = new TextView(context);
            tvDistance.setLayoutParams(params);
            tvDistance.setText(String.valueOf(data.get(i).distance));

            TextView tvResult = new TextView(context);
            tvResult.setLayoutParams(params);
            tvResult.setText(data.get(i).result);

            tableRow.addView(tvDistance);
            tableRow.addView(tvResult);
        }
    }

    private String genRange(int currIndex){
        /********************/
        return somestring;
    }
}

Using table:

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

    <packagename.FlowTable
        android:id="@+id/flowTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

In fragment:

View root = inflater.inflate(R.layout.fragment_session_summary, container, false);
        FlowTable flowTable = (FlowTable)root.findViewById(R.id.flowTable);
        flowTable.addContent(data);

The problem: the screen is just empty! Nothing at all. Before I added the layout params to textview it worked, but row didn’t occupy the screen width. My initial solution was based on the LinearLayout samples, because TableRow is an extention of LinearLayout. But I can’t make it work.
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-27T21:42:45+00:00Added an answer on May 27, 2026 at 9:42 pm

    Try programmatically setting all columns to stretch (didn’t seem to work in XML for me):

    ...
    flowTable.addContent(data);
    flowTable.setStretchAllColumns(true);
    

    Some other quick facts:

    • No need to try and specify height and width for TableRow within TableLayout because it will always be height=WRAP_CONTENT and width=MATCH_PARENT. See TableLayout documentation where this is listed in the Class Overview section
    • No need to try and specify height and widget for children of TableRow because they will always be height=WRAP_CONTENT and width=MATCH_PARENT. See TableRow documentation where this is listed in the Class Overview section

    Might I also humbly suggest a bit of refactoring:

    public class FlowTable extends TableLayout {
        private TableRow mCurrentRow;
    
        public FlowTable(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public FlowTable(Context context) {
            super(context);
            init();
        }
    
        private void init() {
            mCurrentRow = new TableRow(getContext());
            mCurrentRow.addView(createAndFillTextView("0")); // title for first row
            setStretchAllColumns(true);
        }
    
        public void addContent(List<ResultInfo> data) {
            for (int i = 0; i < data.size(); i++) {
                if ((i % 5 == 0) && (i != 0) /** Don't do this on 0! */) {
                    finishRowAndStartNew(i);
                }
    
                mCurrentRow.addView(createAndFillTextView(data.get(i).distance));
                mCurrentRow.addView(createAndFillTextView(data.get(i).result));
            }
        }
    
        private void finishRowAndStartNew(int newRowIndex) {
            addView(mCurrentRow);
            mCurrentRow = new TableRow(getContext());
            mCurrentRow.addView(createAndFillTextView(genRange(newRowIndex+1)));
        }
    
        private String genRange(int currIndex){
            /********************/
            return String.valueOf(currIndex);
        }
    
        private TextView createAndFillTextView(String text) {
            TextView tv = new TextView(getContext());
            tv.setText(text);        
            return tv;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create custom row for ListActivity, each row contains Title and List
i want to crate dynamic table which row contain two check boxes(custom check box)
In C# if I want to create a Custom Event you do something like
The spark panel component for example can be written like this <Panel title=Skinny> <child
I want to create a custom control that extends a built-in control and then
I want to create a simple game.I need this information how to create custom
I want to create a custom button in ActionScript. This is my code: import
I want to create a custom field with multiple values like it may store
I want to create custom labels using UILabel that look like the ones iPhone
I want to create a table layout with custom table rows. Those rows should

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.