Example usage for android.widget TableRow TableRow

List of usage examples for android.widget TableRow TableRow

Introduction

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

Prototype

public TableRow(Context context) 

Source Link

Document

Creates a new TableRow for the given context.

Usage

From source file:com.chess.genesis.dialog.GamePoolDialog.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Game Pool Info");
    setBodyView(R.layout.dialog_gamepool);
    setButtonTxt(R.id.cancel, "Close");

    final TableLayout table = (TableLayout) findViewById(R.id.layout01);
    final LayoutParams layout = (TableRow.LayoutParams) findViewById(R.id.left).getLayoutParams();

    for (final PoolDataItem item : data) {
        final TableRow row = new TableRow(context);

        TextView txt = new TextView(context);
        txt.setLayoutParams(layout);/* ww w.  ja va 2 s  .  c o  m*/
        txt.setText(item.gametype);
        row.addView(txt);

        txt = new TextView(context);
        txt.setText(item.time);
        row.addView(txt);

        table.addView(row);
    }
}

From source file:com.jeffreyawest.weblogic.monitor.activity.display.DisplayEntityActivity.java

public TableRow getRow(int pStringId, String pValue) {

    TableRow row = new TableRow(this);

    TextView textView = new TextView(this);
    textView.setText(getResources().getString(pStringId) + ":");

    float dimension = this.getResources().getDimension(R.dimen.entity_details_table_text_size);

    textView.setTextSize(dimension);//from   w w w .  jav a2s .  c om
    row.addView(textView);

    textView = new TextView(this);
    textView.setText(pValue);
    textView.setTextSize(dimension);
    row.addView(textView);

    return row;
}

From source file:au.org.ala.fielddata.mobile.SurveyBuilder.java

public void buildSurveyForm(View page, int pageNum) {

    TableLayout tableLayout = (TableLayout) page.findViewById(R.id.surveyGrid);
    List<Attribute> pageAttributes = model.getPage(pageNum);

    int rowCount = pageAttributes.size();
    if (pageNum == 0) {
        TableRow row = new TableRow(viewContext);
        buildSurveyName(model.getSurvey(), row);
        addRow(tableLayout, row);//from   w  w  w. j  av a  2 s. c o m
    }
    View previousView = null;
    for (int i = 0; i < rowCount; i++) {
        TableRow row = new TableRow(viewContext);

        Attribute attribute = pageAttributes.get(i);

        View inputView = buildFields(attribute, row);

        configureKeyboardBindings(previousView, inputView);
        binder.configureBindings(inputView, attribute);

        addRow(tableLayout, row);
        previousView = inputView;
    }

}

From source file:com.windnow.StationTextActivity.java

@SuppressLint("RtlHardcoded")
private void printTableRow(String line) {
    TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);

    String[] words = line.split("&/");
    TableRow tr = new TableRow(this);
    TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);/*  www.ja  v a2  s  . c om*/
    params.gravity = Gravity.FILL_HORIZONTAL;
    tr.setLayoutParams(params);

    TableRow.LayoutParams tvParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT);
    tvParams.setMargins(0, 0, 6, 0);

    for (int i = words.length - 1; i >= 0; i--) {
        TextView txv = new TextView(this);
        txv.setLayoutParams(tvParams);
        txv.setText(words[i]);
        txv.setGravity(i == 0 ? Gravity.LEFT : Gravity.LEFT);
        tr.addView(txv, 0);
    }
    tl.addView(tr);
}

From source file:com.mifos.utils.DataTableUIBuilder.java

public LinearLayout getDataTableLayout(final DataTable dataTable, JsonArray jsonElements,
        LinearLayout parentLayout, final Context context, final int entityId,
        DataTableActionListener mListener) {
    dataTableActionListener = mListener;

    /**//  ww  w. ja  v a  2 s .  co  m
     * Create a Iterator with Json Elements to Iterate over the DataTable
     * Response.
     */
    Iterator<JsonElement> jsonElementIterator = jsonElements.iterator();
    /*
     * Each Row of the Data Table is Treated as a Table Here.
     * Creating the First Table for First Row
     */
    tableIndex = 0;
    while (jsonElementIterator.hasNext()) {
        TableLayout tableLayout = new TableLayout(context);
        tableLayout.setPadding(10, 10, 10, 10);

        final JsonElement jsonElement = jsonElementIterator.next();
        /*
        * Each Entry in a Data Table is Displayed in the
        * form of a table where each row contains one Key-Value Pair
        * i.e a Column Name - Column Value from the DataTable
        */
        int rowIndex = 0;
        while (rowIndex < dataTable.getColumnHeaderData().size()) {
            TableRow tableRow = new TableRow(context);
            tableRow.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            tableRow.setPadding(10, 10, 10, 10);
            if (rowIndex % 2 == 0) {
                tableRow.setBackgroundColor(Color.LTGRAY);
            } else {
                tableRow.setBackgroundColor(Color.WHITE);
            }

            TextView key = new TextView(context);
            key.setText(dataTable.getColumnHeaderData().get(rowIndex).getColumnName());
            key.setGravity(Gravity.LEFT);
            TextView value = new TextView(context);
            value.setGravity(Gravity.RIGHT);
            if (jsonElement.getAsJsonObject().get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName())
                    .toString().contains("\"")) {
                value.setText(jsonElement.getAsJsonObject()
                        .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString()
                        .replace("\"", ""));
            } else {
                value.setText(jsonElement.getAsJsonObject()
                        .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString());
            }

            tableRow.addView(key, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            tableRow.addView(value, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams.setMargins(12, 16, 12, 16);
            tableLayout.addView(tableRow, layoutParams);

            rowIndex++;
        }

        tableLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(context, "Update Row " + tableIndex, Toast.LENGTH_SHORT).show();
            }
        });

        tableLayout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {

                Toast.makeText(context, "Deleting Row " + tableIndex, Toast.LENGTH_SHORT).show();

                BaseApiManager baseApiManager = new BaseApiManager();
                DataManager dataManager = new DataManager(baseApiManager);
                Observable<GenericResponse> call = dataManager
                        .removeDataTableEntry(dataTable.getRegisteredTableName(), entityId,
                                Integer.parseInt(jsonElement.getAsJsonObject()
                                        .get(dataTable.getColumnHeaderData().get(0).getColumnName())
                                        .toString()));
                Subscription subscription = call.subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<GenericResponse>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(GenericResponse genericResponse) {
                                Toast.makeText(context, "Deleted Row " + tableIndex, Toast.LENGTH_SHORT).show();
                                dataTableActionListener.onRowDeleted();
                            }
                        });

                return true;
            }
        });

        View v = new View(context);
        v.setBackgroundColor(ContextCompat.getColor(context, R.color.black));
        parentLayout.addView(tableLayout);
        parentLayout.addView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 5));
        Log.i("TABLE INDEX", "" + tableIndex);
        tableIndex++;
    }
    return parentLayout;
}

From source file:lk.ac.mrt.cse.dbs.simpleexpensemanager.ui.ExpenseLogsFragment.java

private void generateTransactionsTable(View rootView, TableLayout logsTableLayout,
        List<Transaction> transactionList) {
    for (Transaction transaction : transactionList) {
        TableRow tr = new TableRow(rootView.getContext());
        TextView lDateVal = new TextView(rootView.getContext());

        SimpleDateFormat sdf = new SimpleDateFormat(getActivity().getString(R.string.config_date_log_pattern));
        String formattedDate = sdf.format(transaction.getDate());
        lDateVal.setText(formattedDate);
        tr.addView(lDateVal);/*from w  w w .ja  v  a  2  s  . com*/

        TextView lAccountNoVal = new TextView(rootView.getContext());
        lAccountNoVal.setText(transaction.getAccountNo());
        tr.addView(lAccountNoVal);

        TextView lExpenseTypeVal = new TextView(rootView.getContext());
        lExpenseTypeVal.setText(transaction.getExpenseType().toString());
        tr.addView(lExpenseTypeVal);

        TextView lAmountVal = new TextView(rootView.getContext());
        lAmountVal.setText(String.valueOf(transaction.getAmount()));
        tr.addView(lAmountVal);

        logsTableLayout.addView(tr);
    }
}

From source file:com.jeffreyawest.weblogic.monitor.charting.DefaultPieChart.java

protected final TableRow getRow(final Activity pActivity, int pColor, String pValue) {

    TableRow row = new TableRow(pActivity);
    row.setPadding(2, 2, 2, 2);/* w w w.  j  a  v a 2 s  .  co  m*/

    pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size);

    TextView colorView = new TextView(pActivity);
    colorView.setBackgroundColor(pColor);
    colorView
            .setHeight((int) pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size));
    colorView.setText("   ");
    colorView.setWidth((int) pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size));
    row.addView(colorView);

    TextView text = new TextView(pActivity);
    text.setText(pValue);
    text.setPadding(2, 2, 2, 2);
    text.setTextSize(15);
    row.addView(text);

    return row;
}

From source file:net.kjmaster.cookiemom.editor.EditDataActivity.java

private void populateTable(final List<CookieTransactions> cookieTransactionsList, Context mContext) {
    edit_data_table.setShrinkAllColumns(true);
    for (final CookieTransactions cookieTransactions : cookieTransactionsList) {
        if ((cookieTransactions.getTransBoxes() != 0) || (cookieTransactions.getTransCash() != 0)) {
            TableRow tr = new TableRow(mContext);
            tr.setTag(cookieTransactions);

            TextView textView = new TextView(mContext);
            textView.setText(java.text.DateFormat.getInstance().format(cookieTransactions.getTransDate()));
            textView.setEnabled(false);/*  ww w  .  j  av  a  2  s. c om*/

            tr.addView(textView);

            TextView textView2 = new TextView(mContext);
            try {
                if (cookieTransactions.getTransScoutId() < 0) {
                    if (cookieTransactions.getTransBoothId() > 0) {
                        textView2.setText(cookieTransactions.getBooth().getBoothLocation());
                    } else {
                        textView2.setText("Cupboard");
                    }
                } else {
                    textView2.setText(cookieTransactions.getScout().getScoutName());
                }
            } catch (Exception e) {
                textView2.setText("");
            }
            textView2.setEnabled(false);
            tr.addView(textView2);

            TextView textView1 = new TextView(mContext);
            textView1.setText(cookieTransactions.getCookieType());
            textView1.setEnabled(false);
            tr.addView(textView1);

            EditText textView3 = new EditText(mContext);
            textView3.setText(cookieTransactions.getTransBoxes().toString());
            textView3.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    if (mActionMode == null) {
                        startActionMode(actionCall);
                    }
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    try {
                        cookieTransactions.setTransBoxes(Integer.valueOf(editable.toString()));

                        cookieTransactionsList.add(cookieTransactions);
                        //Main.daoSession.getCookieTransactionsDao().update(cookieTransactions);
                    } catch (Exception ignored) {
                    }
                }
            });
            tr.addView(textView3);

            EditText textView4 = new EditText(mContext);
            textView4.setText(
                    NumberFormat.getCurrencyInstance().format(cookieTransactions.getTransCash().floatValue()));
            textView4.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    if (mActionMode == null) {
                        startActionMode(actionCall);
                    }
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    try {

                        cookieTransactions.setTransCash(Double.valueOf(editable.toString()));
                        cookieTransactionsList.add(cookieTransactions);

                    } catch (Exception ignored) {
                    }

                }
            });
            tr.addView(textView4);

            edit_data_table.addView(tr);
        }

    }
}

From source file:com.example.android.MainActivity.java

/**Display JSON data in table format on the user interface of android app
 * by clicking on the button 'Start'*/
@Override//ww  w  . ja  v  a2  s.  com
protected void onCreate(Bundle savedInstanceState) {
    /**
     * Declares TextView, Button and Tablelayout to retrieve the widgets 
     * from User Interface. Insert the TableRow into Table and set the 
     * gravity, font size  and id of table rows and columns.
     * 
     * Due to great amount of JSON data, 'for' loop method is used to insert 
     * the new rows and columns in the table. In each loop, each of rows and 
     * columns are set to has its own unique id. This purpose of doing this 
     * is to allows the user to read and write the text of specific rows and 
     * columns easily.
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    progress = new ProgressDialog(this);
    StartDisplay = (Button) findViewById(R.id.btnDisplay);
    profile = (TableLayout) findViewById(R.id.tableLayout1);
    profile.setStretchAllColumns(true);
    profile.bringToFront();

    for (int i = 1; i < 11; i++) {
        TableRow tr = new TableRow(this);
        TextView c1 = new TextView(this);
        TextView c2 = new TextView(this);
        c1.setId(i * 10 + 1);
        c1.setTextSize(12);
        c1.setGravity(Gravity.CENTER);
        c2.setId(i * 10 + 2);
        c2.setTextSize(12);
        c2.setGravity(Gravity.CENTER);
        tr.addView(c1);
        tr.addView(c2);
        tr.setGravity(Gravity.CENTER_HORIZONTAL);
        profile.addView(tr);
    }

    /**
    * onClick: Executes the DownloadWebPageTask once OnClick event occurs. 
    * When user click on the "Start" button, 
    * 1)the JSON data will be read from URL 
    * 2)Progress bar will be shown till all data is read and displayed in
    * table form. Once it reaches 100%, it will be dismissed. 
    * 
    * Progress Bar: The message of the progress bar is obtained from strings.xml.
    * New thread is created to handle the action of the progress bar. 
    */
    StartDisplay.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final String TAG = "MyActivity";
            progress.setMessage(getResources().getString(R.string.ProgressBar_message));
            progress.setCancelable(true);
            progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progress.setProgress(0);
            progress.setMax(100);
            progress.show();
            new Thread(new Runnable() {

                public void run() {
                    while (ProgressBarStatus < 100) {

                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }
                        progressBarbHandler.post(new Runnable() {
                            public void run() {
                                progress.setProgress(ProgressBarStatus);
                            }
                        });
                    }

                    if (ProgressBarStatus >= 100) {

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }

                        progress.dismiss();
                    }
                }
            }).start();
            DownloadWebPageTask task = new DownloadWebPageTask();
            task.execute("http://private-ae335-pgserverapi.apiary.io/user/profile/234");
            StartDisplay.setClickable(false);
        }
    });

}

From source file:de.tobiasbielefeld.solitaire.ui.Statistics.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activty_statistics);

    int padding = (int) getResources().getDimension(R.dimen.statistics_table_padding);
    int textSize = getResources().getInteger(R.integer.statistics_text_size);
    boolean addedEntries = false;
    TableRow row;/*from   w  ww .ja  va2 s. c om*/

    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    tableLayout = (TableLayout) findViewById(R.id.statisticsTableHighScores);
    textWonGames = (TextView) findViewById(R.id.statisticsTextViewGamesWon);
    textWinPercentage = (TextView) findViewById(R.id.statisticsTextViewWinPercentage);

    loadData();

    for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it
        if (scores.get(i, 0) == 0) //if the score is zero, don't show it
            continue;

        if (!addedEntries)
            addedEntries = true;

        row = new TableRow(this);

        TextView textView1 = new TextView(this);
        TextView textView2 = new TextView(this);
        TextView textView3 = new TextView(this);
        TextView textView4 = new TextView(this);

        textView1.setText(String.format(Locale.getDefault(), "%s", scores.get(i, 0)));
        textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", //add it to the view
                scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60, (scores.get(i, 1) % 60)));

        textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.get(i, 2)));
        //textView4.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(scores.get(i,2)));
        textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.get(i, 2)));

        textView1.setPadding(padding, 0, padding, 0);
        textView2.setPadding(padding, 0, padding, 0);
        textView3.setPadding(padding, 0, padding, 0);
        textView4.setPadding(padding, 0, padding, 0);

        textView1.setTextSize(textSize);
        textView2.setTextSize(textSize);
        textView3.setTextSize(textSize);
        textView4.setTextSize(textSize);

        textView1.setGravity(Gravity.CENTER);
        textView2.setGravity(Gravity.CENTER);
        textView3.setGravity(Gravity.CENTER);
        textView4.setGravity(Gravity.CENTER);

        row.addView(textView1);
        row.addView(textView2);
        row.addView(textView3);
        row.addView(textView4);
        row.setGravity(Gravity.CENTER);
        tableLayout.addView(row);
    }
}