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.murrayc.galaxyzoo.app.QuestionFragment.java

private static TableRow addRowToTable(final Activity activity, final TableLayout layoutAnswers) {
    final TableRow row = new TableRow(activity);

    final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.MATCH_PARENT);

    //Add a top margin between this row and any row above it:
    if (layoutAnswers.getChildCount() > 0) {
        final int margin = UiUtils.getPxForDpResource(activity, R.dimen.tiny_gap);
        params.setMargins(0, margin, 0, 0);
    }//from  ww w.  ja  v  a2s  .  co m

    layoutAnswers.addView(row, params);
    return row;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void createTableLayoutTrnDtls() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();/*from  w w  w.j av  a2s.  c o  m*/
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    List<String> trainList;
    if (mTrainDetails == null || mTrainDetails.getPNR() != mPNRNumber) {
        Elements eleTrain = Jsoup.parse(mPageResult).select("table tr tr td:containsOwn(Train Number)");
        Iterator iteTrain = null;
        try {
            iteTrain = eleTrain.first().parent().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("PNRStat", mPageResult);
            return;
        }
        trainList = new ArrayList<String>();
        Element tmp;
        //Get the third row for train details
        iteTrain.next();
        iteTrain.next();
        if (iteTrain.hasNext()) {
            tmp = (Element) iteTrain.next();
            trainList.add(tmp.select("td").get(0).text());
            trainList.add(tmp.select("td").get(1).text());
            trainList.add(tmp.select("td").get(2).text());
            trainList.add(tmp.select("td").get(5).text());
            trainList.add(tmp.select("td").get(6).text());
            trainList.add(tmp.select("td").get(7).text());
        }
        mTrainDetails = new TrainDetails(trainList, mPNRNumber);
    } else {
        trainList = mTrainDetails.getTrainDetails();
    }
    mTableLayoutTrn = new TableLayout(mActivity);
    mTableLayoutTrn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    TableRow row = new TableRow(mActivity);
    mStrTrainDetails = new String();
    row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (String list : trainList) {
        TextView tv = new TextView(mActivity);
        tv.setText(list);
        tv.setPadding(10, 10, 10, 10);
        tv.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
        row.addView(tv);
        mStrTrainDetails += list + " ";
    }
    row.setBackgroundResource(R.drawable.card_background);
    row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    mTableLayoutTrn.addView(row);
}

From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java

private void createTableLayoutTrainFare() {
    if (mPage.contains("SORRY")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Not a valid class, Please select a different class and try again.");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();/*ww  w .j  a va2  s.c om*/
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }
    if (mPage.contains("ISL Of")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("ERROR")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("Network Connectivity")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("unavailable")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText(
                "Response from server:\n\nYour request could not be processed now. \nPlease try again later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) {
        Iterator iterator = null;
        try {
            iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("TrainDetails", mPage);
        }
        mListFr = new ArrayList<List<String>>();
        List<String> list;
        Element tmp;
        while (iterator.hasNext()) {
            tmp = (Element) iterator.next();
            list = new ArrayList<String>();
            list.add(tmp.select("td").get(0).text());
            list.add(tmp.select("td").get(1).text());
            mListFr.add(list);
        }
        mDetails = new Details(mListFr, TrainEnquiry.FARE, mTrainNumber);
    } else {
        mListFr = mDetails.getList();
    }
    mTblLayoutFr = new TableLayout(mActivity);
    TableRow row;
    TextView tv1, tv2;
    mTblLayoutFr.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < mListFr.size(); i++) {
        row = new TableRow(mActivity);
        tv1 = new TextView(mActivity);
        tv2 = new TextView(mActivity);

        tv1.setText("   " + mListFr.get(i).get(0));
        tv2.setText("   " + mListFr.get(i).get(1));

        tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);

        tv1.setPadding(5, 5, 5, 5);
        tv2.setPadding(5, 5, 5, 5);

        /*tv2.setBackgroundResource(R.drawable.card_divider);
        tv3.setBackgroundResource(R.drawable.card_divider);
        tv4.setBackgroundResource(R.drawable.card_divider);*/

        row.addView(tv1);
        row.addView(tv2);

        row.setBackgroundResource(R.drawable.button_selector);
        row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        mTblLayoutFr.addView(row);
    }
    LinearLayout ll = new LinearLayout(mActivity);
    ScrollView scrollView = new ScrollView(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    textViewTrnDtls.setText("Fare details:");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTblLayoutFr);
    scrollView.addView(ll);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(scrollView);
    if (mDialog.isShowing()) {
        mDialog.cancel();
    }
}

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 {/* w  ww .j  a  v  a2  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;
}

From source file:edu.cens.loci.ui.widget.GenericEditorView.java

private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) {

    ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>();

    HashMap<String, APInfoMapItem> apMap = wifi.getAps();
    Set<String> keys = apMap.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext()) {
        String bssid = iter.next();
        APInfoMapItem ap = apMap.get(bssid);
        items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets));
    }// ww w. j a v  a 2  s .c  o  m

    Collections.sort(items);

    table.setColumnCollapsed(0, false);
    table.setColumnCollapsed(1, true);
    table.setColumnShrinkable(0, true);

    for (int i = 0; i < mAddedRows.size(); i++) {
        table.removeView(mAddedRows.get(i));
    }
    mAddedRows.clear();

    int totalCount = wifi.getScanCount();

    Context context = getContext();

    for (WifiViewListItem item : items) {
        TableRow row = new TableRow(context);

        TextView ssidView = new TextView(context);
        ssidView.setText(item.ssid);
        //ssidView.setText("very very very veryvery very very very very very");
        ssidView.setPadding(2, 2, 2, 2);
        ssidView.setTextColor(0xffffffff);

        TextView bssidView = new TextView(context);
        bssidView.setText(item.bssid);
        bssidView.setPadding(2, 2, 2, 2);
        bssidView.setTextColor(0xffffffff);

        TextView cntView = new TextView(context);
        cntView.setText("" + (item.count * 100) / totalCount);
        cntView.setPadding(2, 2, 2, 2);
        cntView.setGravity(Gravity.CENTER);
        cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        TextView rssView = new TextView(context);
        rssView.setText("" + item.rss);
        rssView.setPadding(2, 2, 6, 2);
        rssView.setGravity(Gravity.CENTER);
        rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        row.addView(ssidView, new TableRow.LayoutParams(0));
        row.addView(bssidView, new TableRow.LayoutParams(1));
        row.addView(cntView, new TableRow.LayoutParams(2));
        row.addView(rssView, new TableRow.LayoutParams(3));

        //Log.d(TAG, item.ssid);
        for (int i = 0; i < item.rssBuckets.length; i++) {
            TextView box = new TextView(context);
            box.setText("  ");
            box.setGravity(Gravity.RIGHT);
            box.setPadding(2, 2, 2, 2);
            box.setHeight(15);
            box.setGravity(Gravity.CENTER_VERTICAL);

            float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount());
            //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]);
            int colorValInt = ((int) colorVal) - 1;
            if (colorValInt < 0)
                colorValInt = 0;

            box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan));
            box.setTextColor(0xffffffff);

            row.addView(box, new TableRow.LayoutParams(4 + i));
        }

        row.setGravity(Gravity.CENTER);

        table.addView(row, new TableLayout.LayoutParams());
        table.setColumnStretchable(3, true);
        mAddedRows.add(row);
    }

}

From source file:de.ribeiro.android.gso.dataclasses.Pager.java

/**
 * Erstellt eine Stundeplan Seite des ViewPagers, inkl Header und Footer
 * <p/>//from w  w w.  jav a2s  .c  o  m
 * Hier wird die Wochenansicht generiert
 *
 * @param weekData
 * @param ctxt
 * @return
 * @author Tobias Janssen
 */
private View createWeekPage(WeekData weekData) {
    // in die Page kommen alle Elemente dieser Ansicht
    View page = inflater.inflate(R.layout.weeklayout, null);

    TableLayout tl = (TableLayout) page.findViewById(R.id.weekTimetable);
    LinearLayoutBordered ll = new LinearLayoutBordered(context);

    // Tagesberschrift erstellen:
    TableRow tr = new TableRow(context);

    for (int x = Calendar.SUNDAY; x < Calendar.SATURDAY; x++) {
        // einen neuen Rahmen fr das Tabellenfeld vorbereiten
        ll = new LinearLayoutBordered(context);
        ll.setBorderRight(true);
        ll.setBorderBottom(true);
        ll.setBorderTop(true);
        ll.setBorderSize(1);
        ll.setBackgroundColor(Color.WHITE);

        View textview = inflater.inflate(R.layout.textview, null);
        TextView tv = (TextView) textview.findViewById(R.id.textview);
        // berschriftentextgre einstellen

        tv.setTextSize(textSize);
        if (x == Calendar.SUNDAY) {
            tv.setText(timeslots[0]);
            tv.setTextColor(Color.parseColor("#3A599A"));

        } else {
            tv.setText(ResolveWeekDay(x));
        }
        ll.addView(tv);
        tr.addView(ll);
    }
    tl.addView(tr);

    // den Stundenplan zusammensetzten
    // fr jeden tag
    List<Lesson> stunden = GetSchulstunden();
    for (int y = 0; y < stunden.size(); y++) {
        tr = new TableRow(context);
        for (int x = Calendar.SUNDAY; x <= Calendar.FRIDAY; x++) {
            if (x == Calendar.SUNDAY) {
                addColumn(timeslots[y + 1], "#3A599A", tr);
            } else {
                // alle events dieses Tages durchgehen ob die zu dieser
                // schulstunde passen
                boolean lessonAdded = false;
                TextView lastTextView = null;
                for (ICalEvent ev : weekData.events) {
                    // ist event an diesem tag?
                    if (ev.DTSTART.get(Calendar.DAY_OF_WEEK) == x) {
                        // ja
                        // ist event zu dieser schulstunde?

                        Time st = new Time();
                        st.set(ev.DTSTART.getTimeInMillis());
                        int start = GetSchulstundeOfDateTime(st);
                        Time et = new Time();
                        et.set(ev.DTEND.getTimeInMillis() - 60000);
                        int end = GetSchulstundeOfDateTime(et);
                        // ende der schulstunde herausfinden
                        if (((start != end) && y >= start && y <= end) || start == y || end == y) {
                            // ja event ist in dieser stunde
                            // ist eine Doopelbelegung fr diese Stunde?
                            if (lessonAdded && lastTextView != null) {
                                // ja, doppelbelegung
                                String newText = "";
                                if (weekData.typeId.equalsIgnoreCase("4")) {
                                    newText = lastTextView.getText() + "\r\n" + ev.DESCRIPTION + " "
                                            + ev.SUMMARY;
                                } else {
                                    newText = lastTextView.getText() + "\r\n"
                                            + ev.DESCRIPTION.replace(weekData.elementId, "") + " " + ev.SUMMARY
                                            + " " + ev.LOCATION;
                                }
                                lastTextView.setText(newText);
                            } else {
                                // prfen, ob dieses event eine gelschte
                                // stunde ist
                                if (ev.UID.equalsIgnoreCase("deleted")) {
                                    // gelschtes event
                                    lastTextView = addColumn(" --- " + " " + " --- " + " " + " --- ", "#FF0000",
                                            tr);
                                } else {
                                    String color = "#3A599A";
                                    if (ev.UID.equalsIgnoreCase("diff"))
                                        color = "#FF0000";
                                    if (weekData.typeId.equalsIgnoreCase("4")) {
                                        lastTextView = addColumn(ev.DESCRIPTION + " " + ev.SUMMARY, color, tr);
                                    } else {
                                        lastTextView = addColumn(ev.DESCRIPTION.replace(weekData.elementId, "")
                                                + " " + ev.SUMMARY + " " + ev.LOCATION, color, tr);
                                    }
                                }
                            }

                            lessonAdded = true;
                        }
                    }
                }
                if (!lessonAdded) {
                    // ja event ist in dieser stunde
                    addColumn("", "#3A599A", tr);
                }
            }
        }
        tl.addView(tr);
    }
    TextView syncTime = (TextView) page.findViewById(R.id.syncTime);
    Calendar sync = new GregorianCalendar();
    sync.setTimeInMillis(weekData.syncTime);

    String minute = String.valueOf(sync.get(Calendar.MINUTE));
    if (minute.length() == 1)
        minute = "0" + minute;

    syncTime.setText(weekData.elementId + " | Stand vom " + sync.get(Calendar.DAY_OF_MONTH) + "."
            + (sync.get(Calendar.MONTH) + 1) + "." + sync.get(Calendar.YEAR) + " "
            + sync.get(Calendar.HOUR_OF_DAY) + ":" + minute + " Uhr");

    return page;
}

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

/**
 * Requires tableName to be checked, i.e. isPresent() == true .
 *///from  ww  w .j  ava2  s  .c  om
private void addTitleRowWithSeparator(Context context, float layoutWeightSum, float titleViewWeight) {
    final TableRow tableNameRow = new TableRow(context);
    tableNameRow.setId(ElementsIdProvider.getNextId());
    tableNameRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tableNameRow.setWeightSum(1f);

    titleView = Optional
            .of(getCenteredRowText(context, tableName.get(), layoutWeightSum, true, titleViewWeight));
    tableNameRow.addView(titleView.get());
    addView(tableNameRow, 1);
    addView(constructRowSeparator(1), 2);
    headerOffset += 2;
}

From source file:com.vonglasow.michael.satstat.RadioSectionFragment.java

protected void showCellCdma(CellTowerCdma cell) {
    TableRow row = new TableRow(rilCdmaCells.getContext());
    row.setWeightSum(26);//from w  w w. j a v a  2 s  .  c o m

    TextView newType = new TextView(rilCdmaCells.getContext());
    newType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newType.setTextAppearance(rilCdmaCells.getContext(), android.R.style.TextAppearance_Medium);
    newType.setTextColor(
            rilCdmaCells.getContext().getResources().getColor(getColorFromGeneration(cell.getGeneration())));
    newType.setText(rilCdmaCells.getContext().getResources().getString(R.string.smallDot));
    row.addView(newType);

    TextView newSid = new TextView(rilCdmaCells.getContext());
    newSid.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 6));
    newSid.setTextAppearance(rilCdmaCells.getContext(), android.R.style.TextAppearance_Medium);
    newSid.setText(formatCellData(rilCdmaCells.getContext(), null, cell.getSid()));
    row.addView(newSid);

    TextView newNid = new TextView(rilCdmaCells.getContext());
    newNid.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 5));
    newNid.setTextAppearance(rilCdmaCells.getContext(), android.R.style.TextAppearance_Medium);
    newNid.setText(formatCellData(rilCdmaCells.getContext(), null, cell.getNid()));
    row.addView(newNid);

    TextView newBsid = new TextView(rilCdmaCells.getContext());
    newBsid.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 9));
    newBsid.setTextAppearance(rilCdmaCells.getContext(), android.R.style.TextAppearance_Medium);
    newBsid.setText(formatCellData(rilCdmaCells.getContext(), null, cell.getBsid()));
    row.addView(newBsid);

    TextView newDbm = new TextView(rilCdmaCells.getContext());
    newDbm.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 4));
    newDbm.setTextAppearance(rilCdmaCells.getContext(), android.R.style.TextAppearance_Medium);
    newDbm.setText(formatCellDbm(rilCdmaCells.getContext(), null, cell.getDbm()));
    row.addView(newDbm);

    rilCdmaCells.addView(row,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}

From source file:org.mythdroid.activities.Guide.java

/**
 * Generate a TableRow from the provided Channel
 * @param ch Channel to generate a row for
 * @return populated TableRow representing the channel
 *//*from  www.  j ava2 s  .com*/
@SuppressLint("DefaultLocale")
private TableRow getRowFromChannel(Channel ch) {

    final TableRow row = new TableRow(this);
    row.setLayoutParams(rowLayout);

    TextView tv = new TextView(this);
    tv.setBackgroundColor(0xffe0e0f0);
    tv.setTextColor(0xff202020);
    tv.setPadding(4, 4, 4, 4);
    tv.setMaxLines(2);
    tv.setTag(ch.ID);
    tv.setText(ch.num + " " + ch.callSign); //$NON-NLS-1$
    tv.setOnClickListener(chanClickListener);
    tv.setOnLongClickListener(chanLongClickListener);
    tv.setLayoutParams(chanLayout);

    row.addView(tv);

    LayoutParams layout = null;

    Program[] progs = ch.programs.toArray(new Program[ch.programs.size()]);
    int numprogs = progs.length;

    for (int i = 0; i < numprogs; i++) {

        if (progs[i].StartTime.equals(later))
            continue;

        tv = new TextView(this);
        layout = new LayoutParams(this, null);
        layout.topMargin = layout.bottomMargin = layout.leftMargin = layout.rightMargin = 1;
        layout.height = rowHeight;

        String cat = catPat.matcher(progs[i].Category.toLowerCase()).replaceAll(""); //$NON-NLS-1$

        try {
            tv.setBackgroundColor(Category.valueOf(cat).color());
        } catch (IllegalArgumentException e) {
            tv.setBackgroundColor(Category.unknown.color());
        }

        tv.setTextColor(0xfff0f0f0);
        tv.setPadding(4, 4, 4, 4);
        tv.setMaxLines(2);
        tv.setText(progs[i].Title);
        setStatusDrawable(tv, progs[i]);

        int width = setLayoutParams(layout, progs[i]) * colWidth;
        if (width < 1)
            continue;

        tv.setWidth(width);
        tv.setLayoutParams(layout);
        tv.setTag(progs[i]);
        tv.setOnClickListener(progClickListener);
        row.addView(tv);

    }

    return row;

}

From source file:com.mifos.mifosxdroid.online.generatecollectionsheet.GenerateCollectionSheetFragment.java

private void inflateProductiveCollectionTable(CollectionSheetResponse collectionSheetResponse) {

    //Clear old views in case they are present.
    if (tableProductive.getChildCount() > 0) {
        tableProductive.removeAllViews();
    }//ww w .ja  v  a2 s .  c  o m

    if (tableAdditional.getVisibility() == View.VISIBLE) {
        tableAdditional.removeAllViews();
        tableAdditional.setVisibility(View.GONE);
    }

    //A List to be used to inflate Attendance Spinners
    ArrayList<String> attendanceTypes = new ArrayList<>();
    attendanceTypeOptions.clear();
    attendanceTypeOptions = presenter.filterAttendanceTypes(collectionSheetResponse.getAttendanceTypeOptions(),
            attendanceTypes);

    //Add the heading Row
    TableRow headingRow = new TableRow(getContext());
    TableRow.LayoutParams headingRowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    headingRowParams.gravity = Gravity.CENTER;
    headingRowParams.setMargins(0, 0, 0, 10);
    headingRow.setLayoutParams(headingRowParams);

    TextView tvGroupName = new TextView(getContext());
    tvGroupName.setText(collectionSheetResponse.getGroups().get(0).getGroupName());
    tvGroupName.setTypeface(tvGroupName.getTypeface(), Typeface.BOLD);
    tvGroupName.setGravity(Gravity.CENTER);
    headingRow.addView(tvGroupName);

    for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
        TextView tvProduct = new TextView(getContext());
        tvProduct.setText(getString(R.string.collection_heading_charges, loanProduct.getName()));
        tvProduct.setTypeface(tvProduct.getTypeface(), Typeface.BOLD);
        tvProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvProduct);
    }

    TextView tvAttendance = new TextView(getContext());
    tvAttendance.setText(getString(R.string.attendance));
    tvAttendance.setGravity(Gravity.CENTER);
    tvAttendance.setTypeface(tvAttendance.getTypeface(), Typeface.BOLD);
    headingRow.addView(tvAttendance);

    tableProductive.addView(headingRow);

    for (ClientCollectionSheet clientCollectionSheet : collectionSheetResponse.getGroups().get(0)
            .getClients()) {
        //Insert rows
        TableRow row = new TableRow(getContext());
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        rowParams.gravity = Gravity.CENTER;
        rowParams.setMargins(0, 0, 0, 10);
        row.setLayoutParams(rowParams);

        //Column 1: Client Name and Id
        TextView tvClientName = new TextView(getContext());
        tvClientName.setText(
                concatIdWithName(clientCollectionSheet.getClientName(), clientCollectionSheet.getClientId()));
        row.addView(tvClientName);

        //Subsequent columns: The Loan products
        for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
            //Since there may be several items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the loans in of this type and add in the container
            for (LoanCollectionSheet loanCollectionSheet : clientCollectionSheet.getLoans()) {
                if (loanProduct.getName().equals(loanCollectionSheet.getProductShortName())) {
                    //This loan should be shown in this column. So, add it in the container.
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the loan id as the Tag of the EditText which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_LOAN + ":" + loanCollectionSheet.getLoanId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        Spinner spAttendance = new Spinner(getContext());
        setSpinner(spAttendance, attendanceTypes);
        row.addView(spAttendance);

        tableProductive.addView(row);
    }

    if (btnSubmitProductive.getVisibility() != View.VISIBLE) {
        //Show the button the first time sheet is loaded.
        btnSubmitProductive.setVisibility(View.VISIBLE);
        btnSubmitProductive.setOnClickListener(this);
    }

    //If this block has been executed, that the CollectionSheet
    //which is already shown on screen is for center - Productive.
    btnSubmitProductive.setTag(TAG_TYPE_PRODUCTIVE);
}