Skip to content

1.2 Creating Data to display

Zardozz edited this page Mar 21, 2021 · 2 revisions

To display data inside the FixedHeaderTableLayout you need to create four FixedHeaderSubTableLayout to match the four parts of Table shown below:- Table Overview

The FixedHeaderSubTableLayouts need to be created programmatically as they will usually be containing data that is derived programmatically and they would be tedious to create via XML.

FixedHeaderSubTableLayouts can only contain FixedHeaderTableRow objects which can then contain other view types as cells of the row.

There should be:-

  • The same number of cells (columns) inside each FixedHeaderTableRows that make up each FixedHeaderSubTableLayouts
  • The column Header Table should have the same number of cells (columns) as the main Table
  • The row Header Table should have the same number of rows as the main Table
  • The corner Header Table should have the same number of rows as the column Header Table
  • The corner Header Table should have the same number of cells (columns) as the row Header Table

There is currently no guarantee on the behaviour of a miss shaped set to tables or protection to prevent their creation.
Empty cells should be filled with a "blank" view e.g. a Textview with no text set.

For Example tables can be created by:-

FixedHeaderSubTableLayouts mainTable = new FixedHeaderSubTableLayout(getContext());
        // 25 x 25 in size
        for (int i = 1; i <=25; i++) {
            FixedHeaderTableRow tableRowData = new FixedHeaderTableRow(getContext());
            // Add some data
            for (int j = 1; j <= 25; j++) {
                // Add a Textview
                TextView textView = new TextView(getContext());
                textView.setGravity(Gravity.CENTER);
                textView.setText(String.format(Locale.ROOT,"C%d:R%d", j, i));
                textView.setPadding(5,5,5,5);
                textView.setTextSize(20.0f);
                tableRowData.addView(textView);
            }
            // Add row to the Table
            mainTable.addView(tableRowData);
        }

Creating the four FixedHeaderSubTableLayouts can take enough time that they should not be done on the UI thread, some form of background generation on another thread is advised.