Example usage for android.widget TableLayout post

List of usage examples for android.widget TableLayout post

Introduction

In this page you can find the example usage for android.widget TableLayout post.

Prototype

public boolean post(Runnable action) 

Source Link

Document

Causes the Runnable to be added to the message queue.

Usage

From source file:at.ac.uniklu.mobile.sportal.DashboardUpcomingDatesFragment.java

private void adjustDateListHeight() {
    final TableLayout dateListTable = (TableLayout) getView().findViewById(R.id.dates);
    // post the action to the UI thread to defer execution until the view has been drawn
    dateListTable.post(new Runnable() {
        @Override/*w w w .  j  av  a 2 s  .co  m*/
        public void run() {
            // get first row
            View v = dateListTable.getChildAt(0);
            int entryHeight;
            if (v != null && (entryHeight = v.getMeasuredHeight()) > 0) {
                int numPossibleVisibleRows = dateListTable.getMeasuredHeight() / entryHeight;
                int numExisitingRows = Math.min(numPossibleVisibleRows, dateListTable.getChildCount());
                int numVisibleRows = Math.min(numExisitingRows, numPossibleVisibleRows);
                // remove rows that are outside the screen
                if (numExisitingRows > numVisibleRows) {
                    dateListTable.removeViews(numVisibleRows, numExisitingRows - numVisibleRows);
                }
                // toggle visibility of rows inside the screen
                for (int x = 0; x < numVisibleRows; x++) {
                    dateListTable.getChildAt(x).setVisibility(View.VISIBLE);
                }
            } else {
                Log.d(TAG, "cannot adjust list height");
            }
        }
    });
}