List of usage examples for android.widget TableLayout removeView
@Override public void removeView(View view)
Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.
From source file:com.ultramegasoft.flavordex2.fragment.ViewInfoFragment.java
/** * Populates the table of extra fields.// w w w. ja va 2 s .c o m * * @param data A LinkedHashMap containing the extra values */ protected void populateExtras(@NonNull LinkedHashMap<String, ExtraFieldHolder> data) { final Activity activity = getActivity(); if (activity == null) { return; } final TableLayout table = activity.findViewById(R.id.entry_info); if (!mExtraRows.isEmpty()) { for (View tableRow : mExtraRows) { table.removeView(tableRow); } mExtraRows.clear(); } if (data.size() > 0) { final LayoutInflater inflater = LayoutInflater.from(activity); for (ExtraFieldHolder extra : data.values()) { if (extra.preset) { continue; } final View root = inflater.inflate(R.layout.view_info_extra, table, false); ((TextView) root.findViewById(R.id.label)).setText(getString(R.string.label_field, extra.name)); ((TextView) root.findViewById(R.id.value)).setText(extra.value); table.addView(root); mExtraRows.add(root); } } }
From source file:edu.cens.loci.ui.widget.GenericEditorView.java
private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) { ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>(); HashMap<String, APInfoMapItem> apMap = wifi.getAps(); Set<String> keys = apMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String bssid = iter.next(); APInfoMapItem ap = apMap.get(bssid); items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets)); }// www .j ava 2 s.c o m Collections.sort(items); table.setColumnCollapsed(0, false); table.setColumnCollapsed(1, true); table.setColumnShrinkable(0, true); for (int i = 0; i < mAddedRows.size(); i++) { table.removeView(mAddedRows.get(i)); } mAddedRows.clear(); int totalCount = wifi.getScanCount(); Context context = getContext(); for (WifiViewListItem item : items) { TableRow row = new TableRow(context); TextView ssidView = new TextView(context); ssidView.setText(item.ssid); //ssidView.setText("very very very veryvery very very very very very"); ssidView.setPadding(2, 2, 2, 2); ssidView.setTextColor(0xffffffff); TextView bssidView = new TextView(context); bssidView.setText(item.bssid); bssidView.setPadding(2, 2, 2, 2); bssidView.setTextColor(0xffffffff); TextView cntView = new TextView(context); cntView.setText("" + (item.count * 100) / totalCount); cntView.setPadding(2, 2, 2, 2); cntView.setGravity(Gravity.CENTER); cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); TextView rssView = new TextView(context); rssView.setText("" + item.rss); rssView.setPadding(2, 2, 6, 2); rssView.setGravity(Gravity.CENTER); rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); row.addView(ssidView, new TableRow.LayoutParams(0)); row.addView(bssidView, new TableRow.LayoutParams(1)); row.addView(cntView, new TableRow.LayoutParams(2)); row.addView(rssView, new TableRow.LayoutParams(3)); //Log.d(TAG, item.ssid); for (int i = 0; i < item.rssBuckets.length; i++) { TextView box = new TextView(context); box.setText(" "); box.setGravity(Gravity.RIGHT); box.setPadding(2, 2, 2, 2); box.setHeight(15); box.setGravity(Gravity.CENTER_VERTICAL); float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount()); //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]); int colorValInt = ((int) colorVal) - 1; if (colorValInt < 0) colorValInt = 0; box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan)); box.setTextColor(0xffffffff); row.addView(box, new TableRow.LayoutParams(4 + i)); } row.setGravity(Gravity.CENTER); table.addView(row, new TableLayout.LayoutParams()); table.setColumnStretchable(3, true); mAddedRows.add(row); } }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) { ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>(); HashMap<String, APInfoMapItem> apMap = wifi.getAps(); Set<String> keys = apMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String bssid = iter.next(); APInfoMapItem ap = apMap.get(bssid); items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets)); }//from www .j av a2 s. c om Collections.sort(items); table.setColumnCollapsed(0, false); table.setColumnCollapsed(1, true); table.setColumnShrinkable(0, true); for (int i = 0; i < mAddedRows.size(); i++) { table.removeView(mAddedRows.get(i)); } mAddedRows.clear(); int totalCount = wifi.getScanCount(); for (WifiViewListItem item : items) { TableRow row = new TableRow(this); TextView ssidView = new TextView(this); ssidView.setText(item.ssid); //ssidView.setText("very very very veryvery very very very very very"); ssidView.setPadding(2, 2, 2, 2); ssidView.setTextColor(0xffffffff); TextView bssidView = new TextView(this); bssidView.setText(item.bssid); bssidView.setPadding(2, 2, 2, 2); bssidView.setTextColor(0xffffffff); TextView cntView = new TextView(this); cntView.setText("" + (item.count * 100) / totalCount); cntView.setPadding(2, 2, 2, 2); cntView.setGravity(Gravity.CENTER); cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); TextView rssView = new TextView(this); rssView.setText("" + item.rss); rssView.setPadding(2, 2, 6, 2); rssView.setGravity(Gravity.CENTER); rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); row.addView(ssidView, new TableRow.LayoutParams(0)); row.addView(bssidView, new TableRow.LayoutParams(1)); row.addView(cntView, new TableRow.LayoutParams(2)); row.addView(rssView, new TableRow.LayoutParams(3)); //Log.d(TAG, item.ssid); for (int i = 0; i < item.rssBuckets.length; i++) { TextView box = new TextView(this); box.setText(" "); box.setGravity(Gravity.RIGHT); box.setPadding(2, 2, 2, 2); box.setHeight(15); box.setGravity(Gravity.CENTER_VERTICAL); float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount()); //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]); int colorValInt = ((int) colorVal) - 1; if (colorValInt < 0) colorValInt = 0; box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan)); box.setTextColor(0xffffffff); row.addView(box, new TableRow.LayoutParams(4 + i)); } row.setGravity(Gravity.CENTER); table.addView(row, new TableLayout.LayoutParams()); table.setColumnStretchable(3, true); mAddedRows.add(row); } }
From source file:com.rstar.mobile.thermocouple.ui.FormulaFragment.java
private void displayPolynomial(LayoutInflater inflater) { if (inflater == null) { inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); }/*from w ww. j av a 2s .c om*/ // Remove any existing table LinearLayout parent = mPolynomialView; if (tablePolynomial_Id != 0) { View view = parent.findViewById(tablePolynomial_Id); if (view != null) parent.removeView(view); } int order = -1; if (inputType == inputType_T) { if (fnResult == null) return; order = fnResult.polynomial.getOrder(); } else if (inputType == inputType_E) { if (fnInvResult == null) return; order = fnInvResult.polynomial.getOrder(); } Savelog.d(TAG, debug, "order=" + order); if (order == -1) { return; } int tableSize = 0; tablePolynomial_Id = 0; TableLayout tableLayout = null; if (order >= 0) { View view = inflater.inflate(R.layout.table_polynomial, parent, true); tableLayout = (TableLayout) view.findViewById(R.id.tablePolynomial_id); tableSize = PolynomialTable.MaxOrder; tablePolynomial_Id = R.id.tablePolynomial_id; } // Each row is a term in the polynomial for (int row = 0; row <= order; row++) { int cell_id; int column; int term = row; TextView cell; double coefficient = 0.0; if (inputType == inputType_T) { coefficient = fnResult.polynomial.getCoefficent(term); } else if (inputType == inputType_E) { coefficient = fnInvResult.polynomial.getCoefficent(term); } if (row == order) { column = 0; cell_id = PolynomialTable.cell_ids[row][column]; cell = (TextView) tableLayout.findViewById(cell_id); cell.setText("+"); } column = 1; cell_id = PolynomialTable.cell_ids[row][column]; cell = (TextView) tableLayout.findViewById(cell_id); cell.setText("" + coefficient); column = 2; cell_id = PolynomialTable.cell_ids[row][column]; cell = (TextView) tableLayout.findViewById(cell_id); cell.setText(Html.fromHtml("(" + mInput + ")<sup>" + term + "</sup>")); } for (int row = order + 1; row <= tableSize; row++) { int row_id = PolynomialTable.row_ids[row]; TableRow tableRow = (TableRow) tableLayout.findViewById(row_id); tableLayout.removeView(tableRow); } // The result row shows the value computed by the polynomial { CharSequence sumPolyLabel = ""; String sumPoly = ""; if (inputType == inputType_T) { sumPoly = String.format("%.3f", fnResult.Epoly); sumPolyLabel = EequalLabel; // If there is an exponential term, use a different label if (fnResult.exponential != null) sumPolyLabel = getText(R.string.label_EPequals); } else if (inputType == inputType_E) { sumPoly = String.format("%.3f", fnInvResult.T); sumPolyLabel = TequalLabel; } int result_id; TextView resultCell; result_id = PolynomialTable.result_ids[1]; // column 1 resultCell = (TextView) tableLayout.findViewById(result_id); resultCell.setText(sumPolyLabel); result_id = PolynomialTable.result_ids[2]; // column 2 resultCell = (TextView) tableLayout.findViewById(result_id); resultCell.setText(sumPoly); } }
From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java
private void switchAccountViews() { Spinner accountSpinner = mAccountSpinner.getSpinner(); Spinner transferAccountSpinner = mTransferAccountSpinner.getSpinner(); ViewGroup accountParent = (ViewGroup) findViewById(R.id.AccountRow); ViewGroup transferAccountRow = (ViewGroup) findViewById(R.id.TransferAccountRow); TableLayout table = (TableLayout) findViewById(R.id.Table); View amountRow = table.findViewById(R.id.AmountRow); View transferAmountRow = table.findViewById(R.id.TransferAmountRow); table.removeView(amountRow); table.removeView(transferAmountRow); if (mType == INCOME) { accountParent.removeView(accountSpinner); transferAccountRow.removeView(transferAccountSpinner); accountParent.addView(transferAccountSpinner); transferAccountRow.addView(accountSpinner); table.addView(transferAmountRow, 2); table.addView(amountRow, 4);// ww w .ja va 2 s. c o m } else { accountParent.removeView(transferAccountSpinner); transferAccountRow.removeView(accountSpinner); accountParent.addView(accountSpinner); transferAccountRow.addView(transferAccountSpinner); table.addView(amountRow, 2); table.addView(transferAmountRow, 4); } linkAccountLabels(); }
From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java
/** * Add a row to the provided TableLayout. The row contains an EditText for the field name with a * delete button. The delete button becomes an undo button if the provided listener allows undo. * If undo is not allowed, the delete button will remove the row. * * @param tableLayout The TableLayout to add a row to * @param text The text to fill the text field * @param maxLength The maximum allowed length of the text field * @param hint The hint for the EditText * @param deleteHint The contentDescription for the delete Button * @param deleted The initial deleted status of the field * @param listener The event listener for the field *///from w w w . j a v a2s . c o m private void addTableRow(@NonNull final TableLayout tableLayout, @Nullable String text, int maxLength, int hint, final int deleteHint, final boolean deleted, @NonNull final CatFieldListener listener) { final LayoutInflater inflater = LayoutInflater.from(getContext()); final View root = inflater.inflate(R.layout.edit_cat_field, tableLayout, false); final InputFilter[] filters = new InputFilter[] { new InputFilter.LengthFilter(maxLength) }; final EditText editText = root.findViewById(R.id.field_name); editText.setFilters(filters); editText.setHint(hint); editText.setText(text); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { listener.onNameChange(s.toString()); } }); final ImageButton deleteButton = root.findViewById(R.id.button_delete); deleteButton.setContentDescription(getString(deleteHint)); deleteButton.setOnClickListener(new View.OnClickListener() { private boolean mDeleted = deleted; @Override public void onClick(View v) { if (mDeleted) { setDeleted(false); listener.onUndoDelete(); } else { if (!listener.allowUndo()) { tableLayout.removeView(root); } else { setDeleted(true); } listener.onDelete(); } } private void setDeleted(boolean deleted) { mDeleted = deleted; editText.setEnabled(!deleted); if (deleted) { deleteButton.setImageResource(R.drawable.ic_undo); deleteButton.setContentDescription(getString(R.string.button_undo)); editText.setPaintFlags(editText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { deleteButton.setImageResource(R.drawable.ic_clear); deleteButton.setContentDescription(getString(deleteHint)); editText.setPaintFlags(editText.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } } }); if (deleted) { editText.setEnabled(false); deleteButton.setImageResource(R.drawable.ic_undo); deleteButton.setContentDescription(getString(R.string.button_undo)); editText.setPaintFlags(editText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } tableLayout.addView(root); if (TextUtils.isEmpty(text)) { editText.requestFocus(); } }