Java tutorial
//package com.java2s; /** * LifeStats * Copyright (C) 2014 Yi Zhang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, * with the "Linking Exception", which can be found at the license.txt * file in this program. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * with the "Linking Exception" along with this program; if not, * write to the author Yi Zhang <yi.zhang7210@gmail.com>. * * Acknowledgement: * This app used the GraphView library from: http://www.jjoe64.com/p/graphview-library.html, * and examples from the official Android documentation: http://developer.android.com * and http://stackoverflow.com. */ import android.app.Activity; import android.view.View; import android.widget.Button; import android.widget.TableLayout; import android.widget.TableRow; public class Main { /** * Add button to the layout as the left one on a row. * * @param act The running activity. * @param table The table of buttons. * @param lastRow The previous row of buttons. * @param actName Name of the activity. * @return The Button object that is constructed. */ private static Button addButtonAsFirst(Activity act, TableLayout table, TableRow lastRow, String actName) { /** * Create new row for the table. */ TableRow newRow = new TableRow(act); newRow.setLayoutParams(lastRow.getLayoutParams()); /** * Create both buttons. Set the second invisible. */ Button old = (Button) lastRow.getChildAt(0); Button left = new Button(act); left.setText(actName); left.setLayoutParams(old.getLayoutParams()); Button right = new Button(act); right.setText("TempButton"); right.setLayoutParams(old.getLayoutParams()); right.setVisibility(View.INVISIBLE); /** * Add them on. */ newRow.addView(left); newRow.addView(right); table.addView(newRow); return left; } }