Example usage for android.widget TableLayout removeViewAt

List of usage examples for android.widget TableLayout removeViewAt

Introduction

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

Prototype

public void removeViewAt(int index) 

Source Link

Document

Removes the view at the specified position in the group.

Usage

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

public static void create(Fragment fragment, TableLayout tableLayout, List<Stock> stocks,
        SparseArray<View> tiles, boolean restart) {

    if (restart) {
        tableLayout.removeAllViews();/*  ww w. j  a va  2s . c  om*/
        if (tiles != null) {
            tiles.clear();
        }
    }

    tableLayout.setStretchAllColumns(true);
    tableLayout.setShrinkAllColumns(true);

    int margin = Extensions.dpToPixels(fragment.getResources(), 3);
    int height = Extensions.dpToPixels(fragment.getResources(), 90);

    int index = createFixedHeaderRow(fragment, tableLayout, stocks, tiles, height, margin);

    int row = index == 3 ? 1 : 0;

    while (index < stocks.size()) {
        index = createStandardRow(fragment, tableLayout, stocks, tiles, height, margin, index, row);
        row++;
    }

    while (tableLayout.getChildCount() > row) {
        tableLayout.removeViewAt(tableLayout.getChildCount() - 1);
    }

    if (stocks.size() % 2 != 0) {
        TableRow tableRow = new TableRow(fragment.getActivity());

        View addNewStockTile = createTileForAddingNewStock(fragment);
        tableRow.addView(addNewStockTile, getSpannedLayoutParams(row, margin, height));

        tableLayout.addView(tableRow);
    } else {
        TableRow tableRow = (TableRow) tableLayout.getChildAt(tableLayout.getChildCount() - 1);
        LayoutParams layoutParams = (TableRow.LayoutParams) tableRow.getChildAt(0).getLayoutParams();
        layoutParams.bottomMargin = margin;
        layoutParams.height = height;
    }
}

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

@TargetApi(11)
private static int createStandardRow(Fragment fragment, TableLayout tableLayout, List<Stock> stocks,
        SparseArray<View> tiles, int height, int margin, int index, int row) {

    Stock stock1 = stocks.get(index);//from ww w .j av  a 2 s  .c o m
    Stock stock2 = (index + 1 < stocks.size()) ? stocks.get(index + 1) : null;

    if (shouldUpdateTableRow(tableLayout, row, stock1, stock2)) {
        TableRow tableRow = new TableRow(fragment.getActivity());

        boolean shouldSpanFirstTile = row % 2 != 0;
        boolean shouldSpanSecondTile = !shouldSpanFirstTile;

        if (stock2 != null) {
            View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile);
            tiles.put(index, tile1);
            tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin)
                    : getNotSpannedLayoutParams(row, height, margin));

            View tile2 = createTile(fragment, stock2, index + 1, shouldSpanSecondTile);
            tiles.put(index + 1, tile2);
            tableRow.addView(tile2,
                    shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin)
                            : getLastNotSpannedLayoutParams(row, height, margin));
        } else {
            View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile);
            tiles.put(index, tile1);
            tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin)
                    : getNotSpannedLayoutParams(row, height, margin));

            View tile2 = createTileForAddingNewStock(fragment);
            tiles.put(index + 1, tile2);
            tableRow.addView(tile2,
                    shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin)
                            : getLastNotSpannedLayoutParams(row, height, margin));
        }

        if (row < tableLayout.getChildCount()) {
            tableLayout.removeViewAt(row);
        }

        tableLayout.addView(tableRow, row);
    }

    return index + 2;
}