Example usage for android.widget TableLayout removeAllViews

List of usage examples for android.widget TableLayout removeAllViews

Introduction

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

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:org.mklab.mikity.android.editor.AbstractObjectEditor.java

/**
 * {@inheritDoc}//from w w  w. java  2  s. c o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_object_editor, container, false);

    this.objectType = (TextView) view.findViewById(R.id.objectType);

    final TableLayout parameters = ((TableLayout) view.findViewById(R.id.layout_parameters));
    if (parameters != null) {
        parameters.removeAllViews();
        parameters.setStretchAllColumns(true);
    }

    createColorBoxes(parameters);
    createParameterBoxes(parameters);
    createTranslationBoxes(parameters);
    createRotationBoxes(parameters);

    // Next line should be located after setting the parameters in the boxes
    createButtonComposite(view);

    return view;
}

From source file:org.comixwall.pffw.StatsBase.java

void updateLists(String key) {

    mStats.get(key).totalLabel/*from   w  w w .  ja  v a 2 s  .  c  om*/
            .setText(String.format(getResources().getString(R.string.total_smallcaps), mStats.get(key).total));

    for (String k : statsKeys) {
        TableLayout statsTable = mStats.get(key).statsTables.get(k);
        statsTable.removeAllViews();

        Object[] kvps = mStats.get(key).lists.get(k).entrySet().toArray();
        Arrays.sort(kvps, reverseComparator);

        int count = 1;
        for (Object entry : kvps) {
            TableRow row = (TableRow) getActivity().getLayoutInflater().inflate(R.layout.stats_table_row,
                    new TableRow(this.view.getContext()), true);

            ((TextView) row.findViewById(R.id.tableValue))
                    .setText(((Map.Entry<String, Integer>) entry).getValue().toString());
            ((TextView) row.findViewById(R.id.tableKey)).setText(((Map.Entry<String, Integer>) entry).getKey());
            statsTable.addView(row);

            if (++count > 10) {
                break;
            }
        }
    }
}

From source file:org.mklab.mikity.android.editor.GroupEditor.java

private void createCoordinateParameterBoxes(final View view) {
    final TableLayout parameters = ((TableLayout) view.findViewById(R.id.coordinate_parameters));
    parameters.removeAllViews();
    parameters.setStretchAllColumns(true);

    final TableRow head = new TableRow(getContext());
    final TextView name = new TextView(getContext());
    name.setText(R.string.name);//from   ww  w  .  j  a v a2s . c o m
    name.setTextColor(Color.BLACK);
    final TextView value = new TextView(getContext());
    value.setText(R.string.value);
    value.setTextColor(Color.BLACK);
    head.addView(name);
    head.addView(value);
    parameters.addView(head);

    createCoordinateTranslationBoxes(parameters);
    createCoordinateRotationBoxes(parameters);
}

From source file:org.mklab.mikity.android.editor.GroupEditor.java

private void createAnimationParameterBoxes(final View view) {
    final TableLayout parameters = ((TableLayout) view.findViewById(R.id.animation_parameters));
    parameters.removeAllViews();
    parameters.setStretchAllColumns(true);

    final TableRow head = new TableRow(getContext());
    parameters.addView(head);//from   ww w.java  2s.  c o  m

    final TextView name = new TextView(getContext());
    name.setText(R.string.name);
    name.setTextColor(Color.BLACK);
    head.addView(name);

    final TextView id = new TextView(getContext());
    id.setText(R.string.id);
    id.setTextColor(Color.BLACK);
    head.addView(id);

    final TextView number = new TextView(getContext());
    number.setText(R.string.number);
    number.setTextColor(Color.BLACK);
    head.addView(number);

    createAnimationTranslationBoxes(parameters);
    createAnimationRotationBoxes(parameters);

    setAnimationInDialog();
}

From source file:org.mifos.androidclient.templates.OperationFormActivity.java

public void setOperationSummaryContent(Map<String, String> operationResults) {
    TableLayout operationSummary = (TableLayout) findViewById(R.id.operationForm_operationSummary);
    TableLayoutHelper helper = new TableLayoutHelper(this);
    operationSummary.removeAllViews();
    for (Map.Entry<String, String> entry : operationResults.entrySet()) {
        if (!entry.getKey().equals(STATUS_KEY)) {
            TableRow row = helper.createTableRow();
            TextView cell = helper.createTableCell(
                    ServerMessageTranslator.translate(this, entry.getKey(), entry.getKey()), 1);
            row.addView(cell);//from ww  w .  j a  v  a 2  s  .co m
            cell = helper.createTableCell(
                    ServerMessageTranslator.translate(this, entry.getValue(), entry.getValue()), 2);
            row.addView(cell);
            operationSummary.addView(row);
        }
    }
}

From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleB.java

@Override
protected void initView(final View view, CombinedArrivalInfoStyleB combinedArrivalInfoStyleB) {
    final ArrivalInfo stopInfo = combinedArrivalInfoStyleB.getArrivalInfoList().get(0);
    final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();
    final Context context = getContext();

    LayoutInflater inflater = LayoutInflater.from(context);

    TextView routeName = (TextView) view.findViewById(R.id.routeName);
    TextView destination = (TextView) view.findViewById(R.id.routeDestination);

    // TableLayout that we will fill with TableRows of arrival times
    TableLayout arrivalTimesLayout = (TableLayout) view.findViewById(R.id.arrivalTimeLayout);
    arrivalTimesLayout.removeAllViews();

    Resources r = view.getResources();

    ImageButton starBtn = (ImageButton) view.findViewById(R.id.route_star);
    starBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton mapImageBtn = (ImageButton) view.findViewById(R.id.mapImageBtn);
    mapImageBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton routeMoreInfo = (ImageButton) view.findViewById(R.id.route_more_info);
    routeMoreInfo.setColorFilter(r.getColor(R.color.switch_thumb_normal_material_dark));

    starBtn.setImageResource(/*from  ww w.  ja  v a 2  s.co m*/
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    starBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Show dialog for setting route favorite
            RouteFavoriteDialogFragment dialog = new RouteFavoriteDialogFragment.Builder(
                    stopInfo.getInfo().getRouteId(), stopInfo.getInfo().getHeadsign())
                            .setRouteShortName(stopInfo.getInfo().getShortName())
                            .setRouteLongName(stopInfo.getInfo().getRouteLongName())
                            .setStopId(stopInfo.getInfo().getStopId())
                            .setFavorite(!stopInfo.isRouteAndHeadsignFavorite()).build();

            dialog.setCallback(new RouteFavoriteDialogFragment.Callback() {
                @Override
                public void onSelectionComplete(boolean savedFavorite) {
                    if (savedFavorite) {
                        mFragment.refreshLocal();
                    }
                }
            });
            dialog.show(mFragment.getFragmentManager(), RouteFavoriteDialogFragment.TAG);
        }
    });

    // Setup map
    mapImageBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showRouteOnMap(stopInfo);
        }
    });

    // Setup more
    routeMoreInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showListItemMenu(view, stopInfo);
        }
    });

    routeName.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));

    // Loop through the arrival times and create the TableRows that contains the data
    for (int i = 0; i < combinedArrivalInfoStyleB.getArrivalInfoList().size(); i++) {
        final ArrivalInfo arrivalRow = combinedArrivalInfoStyleB.getArrivalInfoList().get(i);
        final ObaArrivalInfo tempArrivalInfo = arrivalRow.getInfo();
        long scheduledTime = tempArrivalInfo.getScheduledArrivalTime();

        // Create a new row to be added
        final TableRow tr = (TableRow) inflater.inflate(R.layout.arrivals_list_tr_template_style_b, null);

        // Layout and views to inflate from XML templates
        RelativeLayout layout;
        TextView scheduleView, estimatedView, statusView;
        View divider;

        if (i == 0) {
            // Use larger styled layout/view for next arrival time
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_large, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_large, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_large, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large,
                    null);
        } else {
            // Use smaller styled layout/view for further out times
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_small, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_small, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_small, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_small,
                    null);
        }

        // Set arrival times and status in views
        scheduleView.setText(DateUtils.formatDateTime(context, scheduledTime,
                DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));
        if (arrivalRow.getPredicted()) {
            long eta = arrivalRow.getEta();
            if (eta == 0) {
                estimatedView.setText(R.string.stop_info_eta_now);
            } else {
                estimatedView.setText(eta + " min");
            }
        } else {
            estimatedView.setText(R.string.stop_info_eta_unknown);
        }
        statusView.setText(arrivalRow.getStatusText());
        int colorCode = arrivalRow.getColor();
        statusView.setBackgroundResource(R.drawable.round_corners_style_b_status);
        GradientDrawable d = (GradientDrawable) statusView.getBackground();
        d.setColor(context.getResources().getColor(colorCode));

        int alpha;
        if (i == 0) {
            // Set next arrival
            alpha = (int) (1.0f * 255); // X percent transparency
        } else {
            // Set smaller rows
            alpha = (int) (.35f * 255); // X percent transparency
        }
        d.setAlpha(alpha);

        // Set padding on status view
        int pSides = UIUtils.dpToPixels(context, 5);
        int pTopBottom = UIUtils.dpToPixels(context, 2);
        statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom);

        // Add TextViews to layout
        layout.addView(scheduleView);
        layout.addView(statusView);
        layout.addView(estimatedView);

        // Make sure the TextViews align left/center/right of parent relative layout
        RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) scheduleView.getLayoutParams();
        params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params1.addRule(RelativeLayout.CENTER_VERTICAL);
        scheduleView.setLayoutParams(params1);

        RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) statusView.getLayoutParams();
        params2.addRule(RelativeLayout.CENTER_IN_PARENT);
        // Give status view a little extra margin
        int p = UIUtils.dpToPixels(context, 3);
        params2.setMargins(p, p, p, p);
        statusView.setLayoutParams(params2);

        RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) estimatedView.getLayoutParams();
        params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params3.addRule(RelativeLayout.CENTER_VERTICAL);
        estimatedView.setLayoutParams(params3);

        // Add layout to TableRow
        tr.addView(layout);

        // Add the divider, if its not the first row
        if (i != 0) {
            int dividerHeight = UIUtils.dpToPixels(context, 1);
            divider = inflater.inflate(R.layout.arrivals_list_divider_template_style_b, null);
            divider.setLayoutParams(
                    new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, dividerHeight));
            arrivalTimesLayout.addView(divider);
        }

        // Add click listener
        tr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.showListItemMenu(tr, arrivalRow);
            }
        });

        // Add TableRow to container layout
        arrivalTimesLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT));
    }

    // Show or hide reminder for this trip
    ContentValues values = null;
    if (mTripsForStop != null) {
        values = mTripsForStop.getValues(arrivalInfo.getTripId());
    }
    if (values != null) {
        String reminderName = values.getAsString(ObaContract.Trips.NAME);

        TextView reminder = (TextView) view.findViewById(R.id.reminder);
        if (reminderName.length() == 0) {
            reminderName = context.getString(R.string.trip_info_noname);
        }
        reminder.setText(reminderName);
        Drawable d = reminder.getCompoundDrawables()[0];
        d = DrawableCompat.wrap(d);
        DrawableCompat.setTint(d.mutate(), view.getResources().getColor(R.color.theme_primary));
        reminder.setCompoundDrawables(d, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set reminder to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}

From source file:com.ninetwozero.battlelog.fragments.PlatoonStatsFragment.java

public void generateTableRows(TableLayout parent, List<PlatoonStatsItem> stats, boolean isTime) {

    // Make sure the cache is null, as well as the table being cleared
    cacheTableRow = null;//w  ww .jav a  2s .c o  m
    parent.removeAllViews();

    // Loop over them, *one* by *one*
    if (stats != null) {

        // The number of items (-1) as the overall is a field that shouldn't
        // be counted
        int numItems = stats.size() - 1;
        int avg;

        // Iterate over the stats
        for (int i = 0, max = (numItems + 1); i < max; i++) {

            // Set the average
            avg = (i == 0) ? (stats.get(i).getAvg() / numItems) : stats.get(i).getAvg();

            // Is it null?
            cacheView = (RelativeLayout) layoutInflater.inflate(R.layout.grid_item_platoon_stats, null);

            // Add the new TableRow
            if (cacheTableRow == null || (i % 3) == 0) {

                parent.addView(cacheTableRow = new TableRow(context));
                cacheTableRow.setLayoutParams(

                        new TableRow.LayoutParams(

                                TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT

                        )

                );

            }

            // Add the *layout* into the TableRow
            cacheTableRow.addView(cacheView);

            // Set the label
            ((TextView) cacheView.findViewById(R.id.text_label))
                    .setText(stats.get(i).getLabel().toUpperCase() + "");

            // If (i == 0) => Overall
            if (isTime) {

                ((TextView) cacheView.findViewById(R.id.text_average)).setText(PublicUtils.timeToLiteral(avg));
                ((TextView) cacheView.findViewById(R.id.text_max))
                        .setText(PublicUtils.timeToLiteral(stats.get(i).getMax()));
                ((TextView) cacheView.findViewById(R.id.text_mid))
                        .setText(PublicUtils.timeToLiteral(stats.get(i).getMid()));
                ((TextView) cacheView.findViewById(R.id.text_min))
                        .setText(PublicUtils.timeToLiteral(stats.get(i).getMin()));

            } else {

                ((TextView) cacheView.findViewById(R.id.text_average)).setText(avg + "");
                ((TextView) cacheView.findViewById(R.id.text_max)).setText(stats.get(i).getMax() + "");
                ((TextView) cacheView.findViewById(R.id.text_mid)).setText(stats.get(i).getMid() + "");
                ((TextView) cacheView.findViewById(R.id.text_min)).setText(stats.get(i).getMin() + "");

            }

        }

    } else {

        // Create a new row
        parent.addView(cacheTableRow = new TableRow(context));
        cacheTableRow.setLayoutParams(

                new TableRow.LayoutParams(

                        TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT

                )

        );

        // Add a TextView & set it up
        cacheTableRow.addView(cacheView = new TextView(context));
        ((TextView) cacheView).setText(R.string.info_stats_not_found);
        ((TextView) cacheView).setGravity(Gravity.CENTER);

    }

}

From source file:com.bonsai.wallet32.SweepKeyActivity.java

private void updateAccounts() {
    if (mWalletService == null)
        return;/*from w  w  w. jav a 2 s.c  o  m*/

    TableLayout table = (TableLayout) findViewById(R.id.to_choices);

    // Clear any existing table content.
    table.removeAllViews();

    addAccountHeader(table);

    mAccountIds = new ArrayList<Integer>();
    // double sumbtc = 0.0;
    List<Balance> balances = mWalletService.getBalances();
    if (balances != null) {
        for (Balance bal : balances) {
            // sumbtc += bal.balance;
            addAccountRow(table, bal.accountId, bal.accountName, bal.balance,
                    mBTCFmt.fiatAtRate(bal.balance, mFiatPerBTC));
            mAccountIds.add(bal.accountId);
        }
    }
}

From source file:com.acceleratedio.pac_n_zoom.FindTagsActivity.java

private void dsply_tags() {

    TableLayout tbl_tag_lo = (TableLayout) findViewById(R.id.tl_tag);
    int tag_mbr = 0;
    int tag_nmbr = fil_tags.length;
    String lst_str = "";
    int row_mbr;/*from  w  ww.ja  va 2s  . c  o  m*/

    tbl_tag_lo.setAlpha(185);

    // - Find the search string
    srch_str = srch_str.trim();
    boolean flg_srch_tags = !srch_str.equals("");

    if (flg_srch_tags) {

        String[] srch_ary = srch_str.split("\\s* \\s*");
        srch_str = srch_ary[srch_ary.length - 1].toLowerCase();
    }

    // - Remove any current rows
    int row_nmbr = tbl_tag_lo.getChildCount();

    if (row_nmbr > 0)
        tbl_tag_lo.removeAllViews();

    for (row_mbr = 0; row_mbr < 4 && tag_mbr < tag_nmbr; row_mbr++) {

        TableRow tableRow = new TableRow(this);
        tableRow.setGravity(Gravity.CENTER);

        tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT, 1.0f));

        for (int clm_mbr = 0; clm_mbr < 3; clm_mbr++) {

            Button btnTag = new Button(this);

            while (tag_mbr < tag_nmbr
                    && (fil_tags[tag_mbr].equals("") || fil_tags[tag_mbr].equalsIgnoreCase(lst_str)
                            || flg_srch_tags && !fil_tags[tag_mbr].toLowerCase().startsWith(srch_str))) {

                lst_str = fil_tags[tag_mbr];
                tag_mbr++;
            }

            if (tag_mbr >= tag_nmbr)
                break;

            lst_str = fil_tags[tag_mbr];
            btnTag.setText(fil_tags[tag_mbr++]);
            btnTag.setOnClickListener(this);

            btnTag.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                    TableRow.LayoutParams.MATCH_PARENT));

            tableRow.addView(btnTag);
        }

        tbl_tag_lo.addView(tableRow);
    }
}

From source file:com.acceleratedio.pac_n_zoom.SaveAnmActivity.java

private void dsply_tags() {

    TableLayout tbl_tag_lo = (TableLayout) findViewById(R.id.tl_tgs);
    int tag_mbr = 0;
    int tag_nmbr = fil_tags.length;
    String lst_str = "";
    int row_mbr;/*from   w w  w .ja  v a 2  s  .  c  o m*/

    tbl_tag_lo.setAlpha(185);

    // - Find the search string
    srch_str = srch_str.trim();
    boolean flg_srch_tags = !srch_str.equals("");

    if (flg_srch_tags) {

        String[] srch_ary = srch_str.split("\\s* \\s*");
        srch_str = srch_ary[srch_ary.length - 1].toLowerCase();
    }

    // - Remove any current rows
    int row_nmbr = tbl_tag_lo.getChildCount();

    if (row_nmbr > 0)
        tbl_tag_lo.removeAllViews();

    for (row_mbr = 0; tag_mbr < tag_nmbr; row_mbr++) {

        TableRow tableRow = new TableRow(this);
        tableRow.setGravity(Gravity.CENTER);

        tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT, 1.0f));

        int clm_mbr;

        for (clm_mbr = 0; clm_mbr < 3; clm_mbr++) {

            Button btnTag = new Button(this);

            while (tag_mbr < tag_nmbr
                    && (fil_tags[tag_mbr].equals("") || fil_tags[tag_mbr].equalsIgnoreCase(lst_str)
                            || flg_srch_tags && !fil_tags[tag_mbr].toLowerCase().startsWith(srch_str))) {

                lst_str = fil_tags[tag_mbr];
                tag_mbr++;
            }

            if (tag_mbr >= tag_nmbr)
                break;

            lst_str = fil_tags[tag_mbr];
            btnTag.setText(fil_tags[tag_mbr++]);
            btnTag.setOnClickListener(this);

            btnTag.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                    TableRow.LayoutParams.MATCH_PARENT));

            tableRow.addView(btnTag);
        }

        if (clm_mbr > 0)
            tbl_tag_lo.addView(tableRow);
    }
}