private TableRow createByProductRow(dbProduct product, int onboard) { try { CrashReporter.leaveBreadcrumb("MyStockSummary : createByProductRow"); // Create new row to show product stock on truck. TableRow row = (TableRow) inflater.inflate(R.layout.stock_summary_by_product_tablerow, null); row.setTag(product); // In the row set the cell showing the name of the product MyTextView productName = (MyTextView) row.findViewById(R.id.stock_summary_by_product_tablerow_product); productName.setText(product.Desc); // In the row set the cell showing the amount of product on board the truck MyTextView productOnboard = (MyTextView) row.findViewById(R.id.stock_summary_by_product_tablerow_onboard); productOnboard.setText(formatDecimal.format(onboard)); // In the row set the cell showing the volume of surplus product MyTextView surplusProduct = (MyTextView) row.findViewById(R.id.stock_summary_by_product_tablerow_to_load); surplusProduct.setText(formatDecimal.format(0)); // Add the newly created row to the table byProductTable.addView(row); return row; } catch (Exception e) { CrashReporter.logHandledException(e); return null; } }
public void addTableBody(TableLayout table) { Cursor cursor = mySQLiteHelper.executeQuery(this.buildTableQuery()); int row = 0; if (cursor != null && cursor.moveToFirst()) { do { TableRow tr = new TableRow(getActivity()); tr.setGravity(Gravity.CENTER); for (int i = 0; i < columnNames.length; i++) { String value = cursor.getString(cursor.getColumnIndex(columnNames[i])); TextView tv = getCellTextView(value, row); tr.addView(tv); } table.addView(tr); Long id = cursor.getLong(cursor.getColumnIndex("_id")); tr.setTag(id); tr.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Long id = Long.valueOf(v.getTag().toString()); String xml = formBuilder.buildFormSubmissionXMLString(form, id); ((FormDataActivity) getActivity()).switchToDisplayFormFragment(1, xml); } }); row++; } while (cursor.moveToNext()); } }
/** * Creates a row in the data table to store a signal source data (source, date, count, min, max * and avg). */ public void createDataRow(SignalDataSet dataSet) { SignalSource source = dataSet.getSource(); ArrayList<View> containers = AndroidUtil.getViewsByTag(this, dataSet.getId() + "-dataRow"); if (containers.size() == 0) { // There is NO row TableRow row = new TableRow(this); TableRow.LayoutParams lp = new TableRow.LayoutParams( TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); row.setLayoutParams(lp); row.setTag(dataSet.getId() + "-dataRow"); // Signal type. TextView signalType = createDataRowText(dataSet.getId() + "-signalTypeText", source.getSignalType(), 20f); // Source id. TextView sourceId = createDataRowText(dataSet.getId() + "-sourceIdText", source.getId(), 35f); // Record date. TextView date = createDataRowText(dataSet.getId() + "-dateText", "", 20f); // Samples recorded. TextView samplesCount = createDataRowText(dataSet.getId() + "-samplesCountText", "0", 15f); // Min, max and avg. TextView min = createDataRowText(dataSet.getId() + "-minText", "---", 15f); TextView max = createDataRowText(dataSet.getId() + "-maxText", "---", 15f); TextView avg = createDataRowText(dataSet.getId() + "-avgText", "---", 15f); row.addView(signalType); row.addView(sourceId); row.addView(date); row.addView(samplesCount); row.addView(min); row.addView(max); row.addView(avg); TableLayout table = (TableLayout) findViewById(R.id.dataTable); table.addView(row); } }
/** * Creates a row in signals table to store the signal sources checkboxs. Returns the signal * sources checkboxs container. * * @param signalTypeId * @return */ public LinearLayout getSourcesCheckboxsContainer(String signalTypeId) { // Is there already a row for this signal type? LinearLayout checkboxContainer; ArrayList<View> containers = AndroidUtil.getViewsByTag(this, signalTypeId + "-checkboxContainer"); if (containers.size() == 0) { // There is NO row TableRow row = new TableRow(this); TableRow.LayoutParams lp = new TableRow.LayoutParams( TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); row.setLayoutParams(lp); row.setTag(signalTypeId + "-row"); // Signal name. TextView signalType = new TextView(this); signalType.setText(signalTypeId); signalType.setTextColor(Color.BLACK); signalType.setBackgroundResource(R.drawable.table_border); signalType.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f)); signalType.setGravity(Gravity.CENTER); // Signal samples (of each source). EditText signalSamples = new EditText(this); signalSamples.setInputType(InputType.TYPE_CLASS_NUMBER); signalSamples.setBackgroundResource(R.drawable.table_border); signalSamples.setTag(signalTypeId + "-samples"); signalSamples.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f)); signalSamples.setText( Preferences.readString( this.getClass().getSimpleName(), "Signal_" + signalTypeId, DEFAULT_SAMPLES_COUNT + "")); signalSamples.setTextColor(Color.BLACK); signalSamples.setEms(10); // Container for sources checkboxs. checkboxContainer = new LinearLayout(this); checkboxContainer.setOrientation(LinearLayout.HORIZONTAL); checkboxContainer.setTag(signalTypeId + "-checkboxContainer"); // checkboxContainer.setLayoutParams(new TableRow.LayoutParams(0, // TableRow.LayoutParams.MATCH_PARENT, 60f)); LinearLayout left = new LinearLayout(this); left.setOrientation(LinearLayout.VERTICAL); LinearLayout right = new LinearLayout(this); right.setOrientation(LinearLayout.VERTICAL); checkboxContainer.addView(left); checkboxContainer.addView(right); row.addView(signalType); row.addView(signalSamples); ScrollViewWithMaxHeight scrollView = new ScrollViewWithMaxHeight(this); scrollView.setMaxHeight(500); // ScrollView scrollView = new ScrollView(this); scrollView.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 66f)); scrollView.addView(checkboxContainer); row.addView(scrollView); // row.addView(checkboxContainer); TableLayout table = (TableLayout) findViewById(R.id.signalsTable); table.addView(row); } else // There is a row { checkboxContainer = (LinearLayout) containers.get(0); } return checkboxContainer; }