예제 #1
0
  private void addTableRow(String key, String val) {
    TableLayout tl = (TableLayout) findViewById(R.id.data_table);
    TableRow tr = new TableRow(this);
    MarginLayoutParams params =
        new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(TABLE_ROW_MARGIN, TABLE_ROW_MARGIN, TABLE_ROW_MARGIN, TABLE_ROW_MARGIN);
    tr.setLayoutParams(params);
    tr.setBackgroundColor(Color.BLACK);
    TextView name = new TextView(this);
    name.setGravity(Gravity.RIGHT);
    name.setText(key + ": ");
    TextView value = new TextView(this);
    value.setGravity(Gravity.LEFT);
    value.setText(val);
    tr.addView(name);
    tr.addView(value);
    tl.addView(
        tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    /*
     * TODO remove this hack
     *
     * let's define a limit number of rows
     */
    if (tl.getChildCount() > 10) tl.removeViewAt(0);
  }
예제 #2
0
  private TableRow createRow(String key, String value) {
    TableRow row = new TableRow(context);
    TextView pinName = new TextView(context);
    TextView pinValue = new TextView(context);

    row.setLayoutParams(
        new TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    pinName.setText(key);
    pinName.setLayoutParams(new TableRow.LayoutParams(MP, WC, 1));
    pinName.setTextSize(textSize);
    pinValue.setText(value);
    pinValue.setLayoutParams(new TableRow.LayoutParams(MP, WC, 1));
    pinValue.setTextSize(textSize);

    row.addView(pinName);
    row.addView(pinValue);
    return row;
  }