Example usage for android.widget TableRow addView

List of usage examples for android.widget TableRow addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uyi_create_password);
    // Show the Up button in the action bar.
    setupActionBar();/*  w w  w .  ja  va  2s.c o  m*/

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    length = Integer.parseInt(sharedPref.getString("uyi_length", "10"));

    originalViews = new ImageView[length];
    distortedViews = new ImageView[length];
    selectedPictures = new Picture[length];

    Bundle bundle = new Bundle();
    bundle.putInt("length", length);
    DialogFragment intro = new IntroDialogFragment();
    intro.setArguments(bundle);
    intro.show(getFragmentManager(), "intro");

    vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

    Arrays.fill(selectedPictures, null);

    gallery = (Gallery) findViewById(R.id.uyi_gallery_originals);
    gallery.setAdapter(new UYIImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this);
            ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this);

            int i = 0;
            for (; i < selectedPictures.length; i++) {
                if (i == selectedPictures.length - 1 && selectedPictures[i] != null) {
                    removePicture(i);
                }
                if (selectedPictures[i] == null || i == selectedPictures.length - 1) {
                    viewOriginal = originalViews[i];
                    viewDistorted = distortedViews[i];
                    selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position);
                    vibrator.vibrate(100);

                    ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview);
                    int height = originalViews[0].getMeasuredHeight();
                    sv.scrollTo(0, (i * height) - 200);

                    break;
                }
            }

            int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position);
            viewOriginal.setImageResource(originalImageResource);
            viewDistorted.setImageResource(
                    ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position));
            ((UYIImageAdapter) parent.getAdapter()).removePicture(position);

            OnLongClickListener listener = new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    vibrator.vibrate(200);
                    int viewid = v.getId();
                    int index = -1;

                    for (int i = 0; i < originalViews.length; i++) {
                        if (originalViews[i].getId() == viewid) {
                            index = i;
                            break;
                        } else if (distortedViews[i].getId() == viewid) {
                            index = i;
                            break;
                        }
                    }
                    Bundle bundle = new Bundle();
                    bundle.putInt("index", index);
                    DialogFragment dialog = new DeleteImageDialogFragment();
                    dialog.setArguments(bundle);
                    dialog.show(getFragmentManager(), "delete");
                    return false;
                }
            };

            viewOriginal.setOnLongClickListener(listener);
            viewDistorted.setOnLongClickListener(listener);

            // Check
            int count = 0;
            for (int j = 0; j < selectedPictures.length; j++) {
                if (selectedPictures[j] != null) {
                    count++;
                }
            }
            if (count == selectedPictures.length) {
                findViewById(R.id.uyi_save).setClickable(true);
                findViewById(R.id.uyi_save).setEnabled(true);
            }
        }
    });

    table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout);
    LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,
            android.widget.TableRow.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    for (int i = 0; i < length; i++) {
        TableRow row = new TableRow(table.getContext());

        originalViews[i] = new ImageView(row.getContext());
        originalViews[i].setAdjustViewBounds(true);
        originalViews[i].setScaleType(ScaleType.FIT_XY);
        originalViews[i].setPadding(3, 3, 3, 3);
        originalViews[i].setImageResource(R.drawable.oempty);
        originalViews[i].setId(100 + i);

        distortedViews[i] = new ImageView(row.getContext());
        distortedViews[i].setAdjustViewBounds(true);
        distortedViews[i].setScaleType(ScaleType.FIT_XY);
        distortedViews[i].setPadding(3, 3, 3, 3);
        distortedViews[i].setImageResource(R.drawable.wempty);
        distortedViews[i].setId(1000 + i);

        ImageView arrow = new ImageView(row.getContext());
        arrow.setAdjustViewBounds(true);
        arrow.setScaleType(ScaleType.FIT_XY);
        arrow.setMaxWidth(80);
        arrow.setPadding(3, 3, 3, 3);
        arrow.setImageResource(R.drawable.arrow_active);
        arrow.setLayoutParams(params);

        row.addView(originalViews[i]);
        row.addView(arrow);
        row.addView(distortedViews[i]);
        table.addView(row);
    }
}

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
public void showHistory() {
    shPref = ScientificActivity.ctx.getSharedPreferences("myHistpref", 0);
    int inSize = shPref.getInt("HistIndex", 0);
    System.out.println("" + inSize);
    String[] str = new String[inSize];
    for (int inI = 0; inI < inSize; inI++) {
        str[inI] = shPref.getString("hist" + inI, "");
        System.out.println(str[inI]);
    }// ww  w.j ava2s.  c o  m
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    vwLayout = inflater.inflate(R.layout.pop_history,
            (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));

    popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight, true);
    popmW1.setBackgroundDrawable(new BitmapDrawable());
    popmW1.setOutsideTouchable(true);
    popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
    tblltTable = (TableLayout) vwLayout.findViewById(R.id.tablelay);
    ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
    btnCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popmW1.dismiss();

        }
    });
    txtvHistory = new TextView[inSize];
    btnHistory = new Button[inSize];
    tblrRowL = new TableRow[inSize];
    TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, 1f);
    TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, .1f);
    int inJ = 0, inL = inSize - 1;
    for (int inI = 0; inI < inSize; inI++) {
        if (!str[inI].equalsIgnoreCase("")) {
            btnHistory[inJ] = new Button(ctx);
            txtvHistory[inJ] = new TextView(ctx);
            txtvHistory[inJ].setText("" + (inJ + 1));
            txtvHistory[inJ].setGravity(Gravity.CENTER);
            txtvHistory[inJ].setTextColor(ScientificActivity.ctx.getResources().getColor(R.color.HistColor));
            txtvHistory[inJ].setLayoutParams(textParams);
            btnHistory[inJ].setText(str[inL]);
            btnHistory[inJ].setTextColor(Color.WHITE);
            btnHistory[inJ].setGravity(Gravity.LEFT);
            btnHistory[inJ].setLayoutParams(buttonParams);
            btnHistory[inJ].setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.button_effect));
            tblrRowL[inJ] = new TableRow(ctx);
            tblrRowL[inJ].addView(txtvHistory[inJ]);
            tblrRowL[inJ].addView(btnHistory[inJ]);
            tblltTable.addView(tblrRowL[inJ]);
            final int inK = inJ;
            btnHistory[inK].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // etxt.setText(btns[inK].getText().toString());
                    mHandler.insert(btnHistory[inK].getText().toString());
                    popmW1.dismiss();
                }
            });

            inJ++;
            inL--;
        }

    }
    if (inSize == 0) {
        TextView txtvHistory = new TextView(ctx);
        txtvHistory.setLayoutParams(textParams);
        txtvHistory.setGravity(Gravity.CENTER);
        txtvHistory.setTextColor(Color.WHITE);
        txtvHistory.setText("History Empty");
        TableRow tblrRowL = new TableRow(ctx);
        tblrRowL.addView(txtvHistory);
        tblltTable.addView(tblrRowL);
    }
}

From source file:hongik.android.project.best.StoreReviewActivity.java

public void drawTable() throws Exception {
    String query = "func=morereview" + "&license=" + license;
    DBConnector conn = new DBConnector(query);
    conn.start();/*w  w  w . ja v a2 s. c o  m*/

    conn.join();
    JSONObject jsonResult = conn.getResult();
    boolean result = jsonResult.getBoolean("result");

    if (!result) {
        return;
    }

    String storeName = jsonResult.getString("sname");
    ((TextViewPlus) findViewById(R.id.storereview_storename)).setText(storeName);

    JSONArray review = null;
    if (!jsonResult.isNull("review")) {
        review = jsonResult.getJSONArray("review");
    }

    //Draw Review Table
    if (review != null) {
        TableRow motive = (TableRow) reviewTable.getChildAt(1);

        for (int i = 0; i < review.length(); i++) {
            JSONObject json = review.getJSONObject(i);
            final String[] elements = new String[4];
            elements[0] = Double.parseDouble(json.getString("GRADE")) + "";
            elements[1] = json.getString("NOTE");
            elements[2] = json.getString("CID#");
            elements[3] = json.getString("DAY");

            TableRow tbRow = new TableRow(this);
            TextViewPlus[] tbCols = new TextViewPlus[4];

            if (elements[1].length() > 14)
                elements[1] = elements[1].substring(0, 14) + "...";

            for (int j = 0; j < 4; j++) {
                tbCols[j] = new TextViewPlus(this);
                tbCols[j].setText(elements[j]);
                tbCols[j].setLayoutParams(motive.getChildAt(j).getLayoutParams());
                tbCols[j].setGravity(Gravity.CENTER);
                tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(),
                        "InterparkGothicBold.ttf"));
                tbCols[j].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent reviewIntent = new Intent(originActivity, ReviewDetailActivity.class);
                        reviewIntent.putExtra("ACCESS", "STORE");
                        reviewIntent.putExtra("CID", elements[2]);
                        reviewIntent.putExtra("LICENSE", license);
                        Log.i("StoreReview", "StartActivity");
                        startActivity(reviewIntent);
                    }
                });

                Log.i("StoreMenu", "COL" + j + ":" + elements[j]);
                tbRow.addView(tbCols[j]);
            }
            reviewTable.addView(tbRow);
        }
    }
    reviewTable.removeViewAt(1);
}

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 {/*from w w  w .  jav  a 2 s .co 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: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();
    }//from   w  ww . java 2s. 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);
}

From source file:eu.power_switch.gui.adapter.SceneRecyclerViewAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final Scene scene = scenes.get(holder.getAdapterPosition());

    String inflaterString = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater inflater = (LayoutInflater) fragmentActivity.getSystemService(inflaterString);

    holder.sceneName.setText(scene.getName());
    holder.sceneName.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w w  . jav  a2s .c  o m*/
        public void onClick(View v) {
            if (holder.linearLayoutSceneItems.getVisibility() == View.VISIBLE) {
                holder.linearLayoutSceneItems.setVisibility(View.GONE);
            } else {
                holder.linearLayoutSceneItems.setVisibility(View.VISIBLE);
            }
        }
    });
    holder.sceneName.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (onItemLongClickListener != null) {
                onItemLongClickListener.onItemLongClick(v, holder.getAdapterPosition());
            }
            return true;
        }
    });

    holder.buttonActivateScene.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (SmartphonePreferencesHandler.getVibrateOnButtonPress()) {
                VibrationHandler.vibrate(fragmentActivity, SmartphonePreferencesHandler.getVibrationDuration());
            }

            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    ActionHandler.execute(fragmentActivity, scene);
                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });

    // clear previous items
    holder.linearLayoutSceneItems.removeAllViews();
    // hide setup by default
    holder.linearLayoutSceneItems.setVisibility(View.GONE);
    // add current setup
    for (final SceneItem sceneItem : scene.getSceneItems()) {
        // create a new receiverRow for our current receiver and add it
        // to our table of all devices of our current room
        // the row will contain the device name and all buttons
        LinearLayout receiverRow = new LinearLayout(fragmentActivity);
        receiverRow.setOrientation(LinearLayout.HORIZONTAL);
        holder.linearLayoutSceneItems.addView(receiverRow);

        // setup TextView to display receiver name
        AppCompatTextView receiverName = new AppCompatTextView(fragmentActivity);
        receiverName.setText(sceneItem.getReceiver().getName());
        receiverName.setTextSize(18);
        receiverName
                .setTextColor(ThemeHelper.getThemeAttrColor(fragmentActivity, android.R.attr.textColorPrimary));
        receiverName.setGravity(Gravity.CENTER_VERTICAL);
        receiverRow.addView(receiverName,
                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1.0f));

        TableLayout buttonLayout = new TableLayout(fragmentActivity);
        receiverRow.addView(buttonLayout,
                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        int buttonsPerRow;
        if (sceneItem.getReceiver().getButtons().size() % 3 == 0) {
            buttonsPerRow = 3;
        } else {
            buttonsPerRow = 2;
        }

        int i = 0;
        TableRow buttonRow = null;
        for (final Button button : sceneItem.getReceiver().getButtons()) {
            final android.widget.Button buttonView = (android.widget.Button) inflater
                    .inflate(R.layout.simple_button, buttonRow, false);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                buttonView.setElevation(0);
                buttonView.setStateListAnimator(null);
            }
            buttonView.setText(button.getName());
            buttonView.setEnabled(false);

            final int accentColor = ThemeHelper.getThemeAttrColor(fragmentActivity, R.attr.colorAccent);
            final int inactiveColor = ThemeHelper.getThemeAttrColor(fragmentActivity, R.attr.textColorInactive);
            if (sceneItem.getActiveButton().equals(button)) {
                buttonView.setTextColor(accentColor);
            } else {
                buttonView.setTextColor(inactiveColor);
            }

            if (i == 0 || i % buttonsPerRow == 0) {
                buttonRow = new TableRow(fragmentActivity);
                buttonRow.setLayoutParams(
                        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
                buttonRow.addView(buttonView);
                buttonLayout.addView(buttonRow);
            } else {
                buttonRow.addView(buttonView);
            }

            i++;
        }
    }

    if (holder.getAdapterPosition() == getItemCount() - 1) {
        holder.footer.setVisibility(View.VISIBLE);
    } else {
        holder.footer.setVisibility(View.GONE);
    }
}

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

private void inflateCollectionTable(CollectionSheetResponse collectionSheetResponse) {
    //Clear old views in case they are present.
    if (tableProductive.getChildCount() > 0) {
        tableProductive.removeAllViews();
    }/* w  w w.ja v  a  2 s  . c  o  m*/

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

    additionalPaymentTypeMap.clear();
    additionalPaymentTypeMap = presenter.filterPaymentTypes(collectionSheetResponse.getPaymentTypeOptions(),
            paymentTypes);

    //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_loan_product, loanProduct.getName()));
        tvProduct.setTypeface(tvProduct.getTypeface(), Typeface.BOLD);
        tvProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvProduct);
    }

    for (SavingsProduct savingsProduct : collectionSheetResponse.getSavingsProducts()) {
        TextView tvSavingProduct = new TextView(getContext());
        tvSavingProduct.setText(getString(R.string.collection_saving_product, savingsProduct.getName()));
        tvSavingProduct.setTypeface(tvSavingProduct.getTypeface(), Typeface.BOLD);
        tvSavingProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvSavingProduct);
    }

    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 loan : clientCollectionSheet.getLoans()) {
                if (loanProduct.getName().equals(loan.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
                    // in format 'TYPE:ID' which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_LOAN + ":" + loan.getLoanId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        //After Loans, show Savings columns
        for (SavingsProduct product : collectionSheetResponse.getSavingsProducts()) {
            //Since there may be several Savings items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the Savings in of this type and add in the container
            for (SavingsCollectionSheet saving : clientCollectionSheet.getSavings()) {
                if (saving.getProductId() == product.getId()) {
                    //Add the saving 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 Saving id as the Tag of the EditText
                    // in 'TYPE:ID' format which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_SAVING + ":" + saving.getSavingsId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        Spinner spAttendance = new Spinner(getContext());
        //Set the clientId as its tag which will be used as identifier later.
        spAttendance.setTag(clientCollectionSheet.getClientId());
        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 means the CollectionSheet
    //which is already shown is for groups.
    btnSubmitProductive.setTag(TAG_TYPE_COLLECTION);

    if (tableAdditional.getVisibility() != View.VISIBLE) {
        tableAdditional.setVisibility(View.VISIBLE);
    }
    //Show Additional Views
    TableRow rowPayment = new TableRow(getContext());
    TextView tvLabelPayment = new TextView(getContext());
    tvLabelPayment.setText(getString(R.string.payment_type));
    rowPayment.addView(tvLabelPayment);
    Spinner spPayment = new Spinner(getContext());
    setSpinner(spPayment, paymentTypes);
    rowPayment.addView(spPayment);
    tableAdditional.addView(rowPayment);

    TableRow rowAccount = new TableRow(getContext());
    TextView tvLabelAccount = new TextView(getContext());
    tvLabelAccount.setText(getString(R.string.account_number));
    rowAccount.addView(tvLabelAccount);
    EditText etPayment = new EditText(getContext());
    rowAccount.addView(etPayment);
    tableAdditional.addView(rowAccount);

    TableRow rowCheck = new TableRow(getContext());
    TextView tvLabelCheck = new TextView(getContext());
    tvLabelCheck.setText(getString(R.string.cheque_number));
    rowCheck.addView(tvLabelCheck);
    EditText etCheck = new EditText(getContext());
    rowCheck.addView(etCheck);
    tableAdditional.addView(rowCheck);

    TableRow rowRouting = new TableRow(getContext());
    TextView tvLabelRouting = new TextView(getContext());
    tvLabelRouting.setText(getString(R.string.routing_code));
    rowRouting.addView(tvLabelRouting);
    EditText etRouting = new EditText(getContext());
    rowRouting.addView(etRouting);
    tableAdditional.addView(rowRouting);

    TableRow rowReceipt = new TableRow(getContext());
    TextView tvLabelReceipt = new TextView(getContext());
    tvLabelReceipt.setText(getString(R.string.receipt_number));
    rowReceipt.addView(tvLabelReceipt);
    EditText etReceipt = new EditText(getContext());
    rowReceipt.addView(etReceipt);
    tableAdditional.addView(rowReceipt);

    TableRow rowBank = new TableRow(getContext());
    TextView tvLabelBank = new TextView(getContext());
    tvLabelBank.setText(getString(R.string.bank_number));
    rowBank.addView(tvLabelBank);
    EditText etBank = new EditText(getContext());
    rowBank.addView(etBank);
    tableAdditional.addView(rowBank);
}

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

/**
 * Makes the rows for the chalmerstable//  www .j  a v a2  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:de.ribeiro.android.gso.dataclasses.Pager.java

private TextView addColumn(String text, String color, TableRow tr) {
    LinearLayoutBordered ll = new LinearLayoutBordered(context);
    ll = new LinearLayoutBordered(context);
    ll.setBorderRight(true);/*from   w  w  w. j a  v  a  2  s . c om*/
    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);
    tv.setText(text);
    tv.setTextColor(Color.parseColor(color));
    ll.addView(tv);
    tr.addView(ll);
    return tv;
}

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

/**
 * Makes the rows for the lindholmentable
 *///from w w w .ja  v a 2 s  . c  o  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));
    }
}