Example usage for android.widget TableRow setLayoutParams

List of usage examples for android.widget TableRow setLayoutParams

Introduction

In this page you can find the example usage for android.widget TableRow setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:org.smap.smapTask.android.activities.TaskAddressActivity.java

/** Called when the activity is first created. */
@Override//from w w w . j ava 2s . c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.task_address);

    // Get the id of the selected list item
    Bundle bundle = getIntent().getExtras();

    taskEntry = Utilities.getTaskWithId(bundle.getLong("id"));

    try {

        //String assignment_status = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_STATUS));
        //String taskTitle = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_TITLE));
        //String taskAddress = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_ADDRESS));

        // Formatting
        LinearLayout.LayoutParams textLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        textLayout.setMargins(1, 1, 1, 1);

        TableRow.LayoutParams trLayout = new TableRow.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        trLayout.setMargins(1, 1, 1, 1);

        TableLayout tableLayout = (TableLayout) findViewById(R.id.task_address_values);

        // Add Title
        TextView title = (TextView) findViewById(R.id.task_title);
        title.setText(taskEntry.name);

        // Add Status
        TableRow r = new TableRow(this);
        r.setLayoutParams(trLayout);
        r.setBackgroundColor(0xff0000);
        TextView text1 = new TextView(this);
        text1.setText("Status");
        text1.setBackgroundColor(0xff0000);
        TextView text2 = new TextView(this);
        text2.setText(taskEntry.taskStatus);
        text2.setBackgroundColor(0xff0000);
        r.addView(text1);
        r.addView(text2);
        tableLayout.addView(r);

        // Put the Address items in the table
        Type type = new TypeToken<ArrayList<Address>>() {
        }.getType();
        ArrayList<Address> aArray = new Gson().fromJson(taskEntry.taskAddress, type);
        if (aArray != null) {
            for (int i = 0; i < aArray.size(); i++) {

                r = new TableRow(this);
                r.setLayoutParams(trLayout);
                r.setBackgroundColor(0xff0000);

                text1 = new TextView(this);
                text1.setText(aArray.get(i).name);
                text1.setBackgroundColor(0xff0000);

                text2 = new TextView(this);
                text2.setText(aArray.get(i).value);
                text2.setBackgroundColor(0xff0000);

                r.addView(text1);
                r.addView(text2);
                tableLayout.addView(r);
            }
        }

        // Create the buttons
        LinearLayout buttons = (LinearLayout) findViewById(R.id.task_address_buttons);
        //menu.setHeaderTitle(taskTitle);
        if (Utilities.canReject(taskEntry.taskStatus)) {

            Button b = new Button(this);
            b.setText("Reject Task");
            b.setId(R.id.reject_button);
            b.setOnClickListener(this);
            buttons.addView(b);
        }
        if (Utilities.canComplete(taskEntry.taskStatus)) {
            Button b = new Button(this);
            b.setText("Complete Task");
            b.setId(R.id.complete_button);
            b.setOnClickListener(this);
            buttons.addView(b);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:edu.pdx.its.portal.routelandia.ListStat.java

private void buildTable(int rows, int cols, ArrayList<TrafficStat> trafficStats, TableLayout tableLayout) {

    // outer for loop
    for (int i = -1; i < rows; i++) {

        TableRow row = new TableRow(this);
        row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                TableRow.LayoutParams.MATCH_PARENT));

        if (i == -1) {
            for (int j = 0; j < cols; j++) {

                TextView tv = new TextView(this);
                tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.MATCH_PARENT));
                tv.setBackgroundResource(R.drawable.cell_shape);
                tv.setPadding(40, 40, 40, 40);
                tv.setTextColor(Color.BLACK);
                if (j == 0) {
                    tv.setText("Time");
                } else if (j == 1) {
                    tv.setText("Speed");
                } else if (j == 2) {
                    tv.setText("Travel Time");
                } else {
                    tv.setText("Prediction Accuracy");
                }//w  ww  .  j a va  2  s. c  o  m
                row.addView(tv);
            }
        } else {
            // inner for loop
            for (int j = 0; j < cols; j++) {

                TextView tv = new TextView(this);
                tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.MATCH_PARENT));
                tv.setBackgroundResource(R.drawable.cell_shape);
                tv.setPadding(40, 40, 40, 40);
                tv.setTextColor(Color.BLACK);
                if (j == 0) {
                    if (trafficStats.get(i).getMinutes() == 0) {

                        tv.setText(trafficStats.get(i).getHour() + ":" + trafficStats.get(i).getMinutes()
                                + trafficStats.get(i).getMinutes());

                    } else {
                        tv.setText(trafficStats.get(i).getHour() + ":" + trafficStats.get(i).getMinutes());
                    }
                } else if (j == 1) {
                    tv.setText(trafficStats.get(i).getSpeed() + " MPH");
                } else if (j == 2) {
                    tv.setText(trafficStats.get(i).getTravelTime() + " Min");
                } else {
                    tv.setText(trafficStats.get(i).getAccuracy() + "%");
                }

                row.addView(tv);

            }
        }

        tableLayout.addView(row);

    }
}

From source file:itesm.mx.golpedecalor.MonitoringActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_monitoring);

    alerta = false;/*from  ww w  .  ja  v  a  2  s . co m*/

    dbo = new DataBaseOperations(getApplicationContext());
    groupId = getIntent().getLongExtra("id", 0);

    // Referencias a objetos de interfacae
    tablaTL = (TableLayout) findViewById(R.id.tablaTL);
    nombreTV = (TextView) findViewById(R.id.nombreTV);
    causaTV = (TextView) findViewById(R.id.causaTV);
    parametroTV = (TextView) findViewById(R.id.parametroTV);
    switcherVS = (ViewSwitcher) findViewById(R.id.switcherVS);
    mp = MediaPlayer.create(this, R.raw.alert);
    recomendacionesTV = (TextView) findViewById(R.id.recomendacionesTV);

    // Inicializacin
    rc = new ArrayList<TextView>();
    temp = new ArrayList<TextView>();
    rad = new ArrayList<TextView>();

    try {
        dbo.open();
    } catch (SQLException ex) {
        Log.e("", ex.toString());
    }

    grupo = dbo.getGroup(groupId);
    grupo.setIntegrantes(dbo.getAllUsersFromGroup(grupo));
    monitoreoHelper = new Monitoreo(grupo, this);

    for (Usuario u : grupo.getIntegrantes()) {
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                TableRow.LayoutParams.FILL_PARENT));

        TextView tvAux = new TextView(this);
        tvAux.setText(u.getNombre() + " " + u.getApellidos());
        tvAux.setLayoutParams(new TableRow.LayoutParams(400, TableRow.LayoutParams.WRAP_CONTENT));

        TextView rcAux = new TextView(this);
        rcAux.setText("5");
        rcAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT));

        TextView tempAux = new TextView(this);
        tempAux.setText("9");
        tempAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT));

        TextView radAux = new TextView(this);
        radAux.setText("10");
        radAux.setLayoutParams(new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT));

        rc.add(rcAux);
        temp.add(tempAux);
        rad.add(radAux);

        tr.addView(tvAux);
        tr.addView(rcAux);
        tr.addView(tempAux);
        tr.addView(radAux);

        tr.setBackgroundResource(R.drawable.tabla); // Asigna recurso de drawable a la row nueva
        tablaTL.addView(tr);
    }
    monitoreoHelper.empezarMonitoreo();

    notificationIntent = new Intent(getApplicationContext(), NotificationActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                monitoreoHelper.terminarAlerta();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                //No button clicked
                break;
            }
        }
    };

}

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 .  java 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);
    }
}

From source file:com.chalmers.schmaps.CheckBusActivity.java

/**
 * Makes the rows for the chalmerstable//from  w  ww .  j  a  v a  2 s .  c  o  m
 */
public void makeChalmersRows() {
    for (int i = 0; i < NROFROWS; i++) {
        TableRow tempTableRow = new TableRow(this);
        tempTableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        // Makes every other row light gray or white
        if (i % 2 == 0) {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_grey));
        } else {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_white));
        }

        //Makes every textview for each column and add it before starting with a new one
        for (int j = 0; j < NR_OF_COLUMNS; j++) {
            TextView textview = new TextView(this);
            textview.setTextColor(Color.BLACK);
            textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
            //Check which content should be written in the textview
            if (j == COLUMN_NR_1) {
                textview.setText(chalmersLineArray.get(i));
            } else if (j == COLUMN_NR_2) {
                textview.setText(chalmersDestArray.get(i));
            } else if (j == COLUMN_NR_3) {
                textview.setText(chalmersTimeArray.get(i));
            } else if (j == COLUMN_NR_4) {
                textview.setText(chalmersTrackArray.get(i));
            }
            textview.setGravity(Gravity.CENTER_HORIZONTAL);
            tempTableRow.addView(textview);
        }
        chalmersTable.addView(tempTableRow,
                new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.chalmers.schmaps.CheckBusActivity.java

/**
 * Makes the rows for the lindholmentable
 *///ww  w. j  a  va2 s . co m
public void makeLindholmenRows() {
    for (int i = 0; i < NROFROWS; i++) {
        TableRow tempTableRow = new TableRow(this);
        tempTableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        // Makes every other row light gray or white
        if (i % 2 == 0) {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_grey));
        } else {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_white));
        }

        //Makes every textview for each column and add it before starting with a new one 
        for (int j = 0; j < NR_OF_COLUMNS; j++) {
            TextView textview = new TextView(this);
            textview.setTextColor(Color.BLACK);
            textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
            //Check which content should be written in the textview
            if (j == COLUMN_NR_1) {
                textview.setText(lindholmenLineArray.get(i));
            } else if (j == COLUMN_NR_2) {
                textview.setText(lindholmenDestArray.get(i));
            } else if (j == COLUMN_NR_3) {
                textview.setText(lindholmenTimeArray.get(i));
            } else if (j == COLUMN_NR_4) {
                textview.setText(lindholmenTrackArray.get(i));
            }

            textview.setGravity(Gravity.CENTER_HORIZONTAL);
            tempTableRow.addView(textview);
        }
        lindholmenTable.addView(tempTableRow,
                new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java

@SuppressLint("NewApi")
@Override/*from   w ww.  ja  va  2  s. co  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_summary, container, false);

    final MainActivity activity = (MainActivity) getActivity();
    final Context context = activity;
    final Resources resources = context.getResources();

    // Get the model and attach a listener.
    game = activity.getGame();
    if (game != null) {
        game.addListener(mGameListener);
    }

    players = activity.getPlayers();

    // Get resources.
    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] playerTextColorsIds = new int[playerTextColorsArray.length()];
    for (int i = 0; i < playerTextColorsArray.length(); i++) {
        playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1);
    }

    // Get root view.
    ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);

    // Create table.
    tableLayout = new TableLayout(context);
    TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableLayout.setLayoutParams(tableLayoutParams);
    scrollView.addView(tableLayout);

    // Add header.
    {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.player));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.trains));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.contracts));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.bonuses));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

    }

    // Add rows.
    for (int i = 0; i < players.getNum(); i++) {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        ToggleButton toggleButton = new ToggleButton(context);
        toggleButton.setGravity(Gravity.CENTER);
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setText(playerNames[i]);
        toggleButton.setClickable(false);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i]));
        row.addView(toggleButton);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

    }

    Bundle args = getArguments();
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    drawablesArray.recycle();
    playerTextColorsArray.recycle();

    // final int index = args.getInt(ARG_INDEX);
    // final String tabSpec = args.getString(ARG_TAB_SPEC);

    return rootView;
}

From source file:com.health.openscale.gui.TableFragment.java

@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList) {
    TableRow headerRow = (TableRow) tableView.findViewById(R.id.tableHeader);
    tableDataView.removeAllViews();/*from w  w  w.  j  a v a  2s  .  c  o  m*/
    tableDataView.addView(headerRow);

    for (ScaleData scaleData : scaleDataList) {
        TableRow dataRow = new TableRow(tableView.getContext());
        dataRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        TextView idView = new TextView(tableView.getContext());
        idView.setText(Long.toString(scaleData.id));
        idView.setVisibility(View.GONE);
        dataRow.addView(idView);

        TextView dateTextView = new TextView(tableView.getContext());
        if ((getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE
                || (getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
            dateTextView.setText(new SimpleDateFormat("dd. MMM yyyy (EE)").format(scaleData.date_time));
        } else {
            dateTextView.setText(new SimpleDateFormat("dd/MM/yy").format(scaleData.date_time));
        }
        dateTextView.setPadding(0, 5, 5, 5);
        dataRow.addView(dateTextView);

        TextView timeTextView = new TextView(tableView.getContext());
        timeTextView.setText(new SimpleDateFormat("HH:mm").format(scaleData.date_time));
        timeTextView.setPadding(0, 5, 5, 5);
        dataRow.addView(timeTextView);

        TextView weightView = new TextView(tableView.getContext());
        weightView.setText(Float.toString(scaleData.weight));
        weightView.setPadding(0, 5, 5, 5);
        dataRow.addView(weightView);

        TextView fatView = new TextView(tableView.getContext());
        fatView.setText(Float.toString(scaleData.fat));
        fatView.setPadding(0, 5, 5, 5);
        dataRow.addView(fatView);

        TextView waterView = new TextView(tableView.getContext());
        waterView.setText(Float.toString(scaleData.water));
        waterView.setPadding(0, 5, 5, 5);
        dataRow.addView(waterView);

        TextView muscleView = new TextView(tableView.getContext());
        muscleView.setText(Float.toString(scaleData.muscle));
        muscleView.setPadding(0, 5, 5, 5);
        dataRow.addView(muscleView);

        Button deleteButton = new Button(tableView.getContext());
        deleteButton.setText("X");
        deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
        deleteButton.setTextColor(Color.WHITE);
        deleteButton.setBackgroundResource(R.drawable.flat_selector);
        deleteButton.setGravity(Gravity.CENTER);
        deleteButton.setPadding(0, 0, 0, 0);
        deleteButton.setMinimumHeight(35);
        deleteButton.setHeight(35);
        deleteButton.setOnClickListener(new onClickListenerDelete());
        dataRow.addView(deleteButton);

        if ((getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE
                && (getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE) {
            dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            weightView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            fatView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            waterView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            muscleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
        }

        tableDataView.addView(dataRow,
                new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

private TableRow makeTableRow(TextView label, TextView value) {
    TableRow tableRow = new TableRow(getActivity());
    tableRow.setLayoutParams(
            new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    tableRow.addView(label);/*www .  j  a va  2  s.  c o  m*/
    if (value != null) {
        tableRow.addView(value);
    }
    return tableRow;
}

From source file:com.money.manager.ex.home.DashboardFragment.java

private TableRow createTableRow(String[] fields, Float[] weight, Integer[] gravity, Integer[][] margin) {
    // create row
    TableRow row = new TableRow(getActivity());
    row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < fields.length; i++) {
        RobotoTextView txtField = new RobotoTextView(getActivity(), null);
        TableRow.LayoutParams layoutParams;
        if (weight[i] != null) {
            layoutParams = new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, weight[i]);
        } else {/*www  .java2  s.  c  o m*/
            layoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        }
        // set margin
        if (margin[i] != null)
            layoutParams.setMargins(margin[i][0], margin[i][1], margin[i][2], margin[i][3]);
        txtField.setLayoutParams(layoutParams);
        if (gravity[i] != null)
            txtField.setGravity(gravity[i]);
        // set text
        txtField.setText(Html.fromHtml(fields[i]));
        // set singleline
        txtField.setSingleLine(true);
        // add field
        row.addView(txtField);
    }
    // return row
    return row;
}