Example usage for android.widget TableLayout getChildCount

List of usage examples for android.widget TableLayout getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:Main.java

/**
 * Clears all of the TableRows from a TableLayout, with the EXCEPTION
 * of the first row! The first row should be the component category
 * (Situps, Pushups, Run, Waist) and should therefore never be deleted.
 * @param table//from  w ww. j a v a2 s .  c o  m
 */
public static void clearAfiTable(TableLayout table) {
    int count = table.getChildCount();
    for (int i = 1; i < count; i++) {
        View child = table.getChildAt(i);
        if (child instanceof TableRow)
            ((ViewGroup) child).removeAllViews();
    }
}

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

public static void create(Fragment fragment, TableLayout tableLayout, List<Stock> stocks,
        SparseArray<View> tiles, boolean restart) {

    if (restart) {
        tableLayout.removeAllViews();/*from   w  w  w .ja  v  a 2 s .  c o m*/
        if (tiles != null) {
            tiles.clear();
        }
    }

    tableLayout.setStretchAllColumns(true);
    tableLayout.setShrinkAllColumns(true);

    int margin = Extensions.dpToPixels(fragment.getResources(), 3);
    int height = Extensions.dpToPixels(fragment.getResources(), 90);

    int index = createFixedHeaderRow(fragment, tableLayout, stocks, tiles, height, margin);

    int row = index == 3 ? 1 : 0;

    while (index < stocks.size()) {
        index = createStandardRow(fragment, tableLayout, stocks, tiles, height, margin, index, row);
        row++;
    }

    while (tableLayout.getChildCount() > row) {
        tableLayout.removeViewAt(tableLayout.getChildCount() - 1);
    }

    if (stocks.size() % 2 != 0) {
        TableRow tableRow = new TableRow(fragment.getActivity());

        View addNewStockTile = createTileForAddingNewStock(fragment);
        tableRow.addView(addNewStockTile, getSpannedLayoutParams(row, margin, height));

        tableLayout.addView(tableRow);
    } else {
        TableRow tableRow = (TableRow) tableLayout.getChildAt(tableLayout.getChildCount() - 1);
        LayoutParams layoutParams = (TableRow.LayoutParams) tableRow.getChildAt(0).getLayoutParams();
        layoutParams.bottomMargin = margin;
        layoutParams.height = height;
    }
}

From source file:com.dicent.DiceFragment.java

public void redraw() {
    TableLayout tl = (TableLayout) getView().findViewById(R.id.diceTable);
    for (int i = 0; i < tl.getChildCount(); i++) { // table rows
        TableRow row = (TableRow) tl.getChildAt(i);
        for (int j = 0; j < row.getChildCount(); j++) { // dice
            row.getChildAt(j).invalidate();
        }/*w  w  w.ja  va  2  s  . c o  m*/
    }
}

From source file:com.cybrosys.basic.BasicActivity.java

@Override
public void onStart() {
    super.onStart();
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    ctx = getActivity();/*  www  .  ja va2  s.  c  o m*/
    init();
    mDisplay = (CalculatorDisplay) getView().findViewById(R.id.display);
    imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    mDisplay = (CalculatorDisplay) getView().findViewById(R.id.display);

    mPersist = new Persist(ctx);
    mPersist.load();
    mHistory = mPersist.history;
    mLogic = new Logic(ctx, mHistory, mDisplay);
    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());
    HistoryAdapter historyAdapter = new HistoryAdapter(ctx, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    btnmul = (Button) getView().findViewById(R.id.btnmul);
    btnmul.setText(Html.fromHtml("x"));
    btnminus = (Button) getView().findViewById(R.id.btnminus);
    btnminus.setText(Html.fromHtml("-"));

    // tablelayout of numbers
    TableLayout tblltPad = (TableLayout) getView().findViewById(R.id.tabcalc);
    int inPadCount = tblltPad.getChildCount();

    for (int inI = 0; inI < inPadCount; inI++) {
        View vwView = tblltPad.getChildAt(inI);
        if (vwView instanceof TableRow) {
            TableRow tblrRow = (TableRow) vwView;
            int inRowCount = tblrRow.getChildCount();
            for (int inR = 0; inR < inRowCount; inR++) {
                View v2 = tblrRow.getChildAt(inR);
                if (v2 instanceof Button) {
                    Button b = (Button) v2;
                    if (b.getId() == R.id.buttonDel) {
                        b.setOnLongClickListener(new View.OnLongClickListener() {
                            @Override
                            public boolean onLongClick(View v) {
                                mLogic.onClear();
                                return true;
                            }
                        });
                    }
                    // setting on click listener for the buttons
                    b.setOnClickListener(mListener);
                }
            }
        }
    }
    mDisplay.setText(myString, null);

}

From source file:org.xingjitong.ContactFragment.java

private void displayContact(LayoutInflater inflater, View view) {
    AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    if (contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(),
                contact.getID());//from  www . ja va2 s  .c  o  m
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
        contactPicture.setImageResource(R.drawable.unknown_small);
    }

    TextView contactName = (TextView) view.findViewById(R.id.contactName);
    contactName.setText(contact.getName());
    contactName.setTextColor(Color.BLACK);
    View view2 = inflater.inflate(R.layout.edit_contact, null);
    TableLayout controls = (TableLayout) view2.findViewById(R.id.controls);
    if (controls.getChildCount() > 0 && controls != null) {
        controls.removeAllViews();
    }
    for (String numberOrAddress : contact.getNumerosOrAddresses()) {
        //yyppdialog
        View v = inflater.inflate(R.layout.contact_control_row, null);

        String displayednumberOrAddress = numberOrAddress;
        if (numberOrAddress.startsWith("sip:")) {
            displayednumberOrAddress = displayednumberOrAddress.substring(4);
        }

        TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
        tv.setText(displayednumberOrAddress);
        tv.setSelected(true);

        if (!displayChatAddressOnly) {
            //yyppcontact //yyppdialog
            v.findViewById(R.id.dial).setOnClickListener(dialListener);
            v.findViewById(R.id.dial).setTag(displayednumberOrAddress);
        } else {

            v.findViewById(R.id.dial).setVisibility(View.GONE);
        }

        v.findViewById(R.id.chat).setOnClickListener(chatListener);
        if (LinphoneUtils.isSipAddress(numberOrAddress)) {
            v.findViewById(R.id.chat).setTag(numberOrAddress);
        } else {
            LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
            if (lpc != null) {
                if (!numberOrAddress.startsWith("sip:")) {
                    numberOrAddress = "sip:" + numberOrAddress;
                }
                v.findViewById(R.id.chat).setTag(numberOrAddress + "@" + lpc.getDomain());
            }
        }

        final String finalNumberOrAddress = numberOrAddress;
        ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
        if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
            friend.setVisibility(View.VISIBLE);

            boolean isAlreadyAFriend = LinphoneManager.getLc()
                    .findFriendByAddress(finalNumberOrAddress) != null;
            if (!isAlreadyAFriend) {
                friend.setImageResource(R.drawable.friend_add);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            } else {
                friend.setImageResource(R.drawable.friend_remove);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            }
        }

        if (getResources().getBoolean(R.bool.disable_chat)) {
            v.findViewById(R.id.chat).setVisibility(View.GONE);
        }

        controls.addView(v);
    }
}

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

@Override
public void onStart() {
    super.onStart();
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    ctx = getActivity();/*  w  w w.  j  a v  a2s  .  c  om*/
    init();
    mDisplay = (CalculatorDisplay) getView().findViewById(R.id.display);
    imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    mDisplay = (CalculatorDisplay) getView().findViewById(R.id.display);
    metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    inDispheight = (int) (metrics.heightPixels * .6f);
    inDispwidth = (int) (metrics.widthPixels * .8f);
    mPersist = new Persist(ctx);
    mPersist.load();
    mHistory = mPersist.history;
    mLogic = new Logic(ctx, mHistory, mDisplay);
    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());
    HistoryAdapter historyAdapter = new HistoryAdapter(ctx, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    // tablelayout for the functions
    TableLayout tblltPad = (TableLayout) getView().findViewById(R.id.tableLayout1);
    int inPadCount = tblltPad.getChildCount();

    for (int inI = 0; inI < inPadCount; inI++) {
        View vwView = tblltPad.getChildAt(inI);
        if (vwView instanceof TableRow) {
            TableRow tblrRow = (TableRow) vwView;
            int inRowCount = tblrRow.getChildCount();
            for (int inR = 0; inR < inRowCount; inR++) {
                View v2 = tblrRow.getChildAt(inR);
                if (v2 instanceof Button) {
                    Button b = (Button) v2;
                    // setting listeners for the function buttons
                    b.setOnClickListener(mListener);
                    b.setOnLongClickListener(mListener);
                } else if (v2 instanceof TextView) {
                    TextView txtv = (TextView) v2;
                    txtv.setOnClickListener(null);
                }
            }
        }
    }
    // tablelayout for the numbers
    TableLayout tblltNum = (TableLayout) getView().findViewById(R.id.tableLayout2);
    int inNumcount = tblltNum.getChildCount();

    mDisplay.setText(myString, null);
    txtvFSE.setText(strFSEstate);
    txtvShift.setText(strAlt);
    txtvDeg.setText(strDeg);
    txtvHyp.setText(strHyp);

    for (int inI = 0; inI < inNumcount; inI++) {
        View vw1 = tblltNum.getChildAt(inI);
        if (vw1 instanceof TableRow) {
            TableRow tblrRow = (TableRow) vw1;
            int inRowCount = tblrRow.getChildCount();
            for (int inR = 0; inR < inRowCount; inR++) {
                View vw2 = tblrRow.getChildAt(inR);
                if (vw2 instanceof Button) {
                    Button b = (Button) vw2;
                    // setting listeners for the buttons
                    b.setOnClickListener(mListener);
                    b.setOnLongClickListener(mListener);
                } else if (vw2 instanceof TextView) {
                    TextView txtv = (TextView) vw2;
                    txtv.setOnClickListener(null);
                }
            }
        }
    }

}

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 w w  w. java 2 s  .  c  om

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

From source file:de.domjos.schooltools.activities.MainActivity.java

public static void initTimes(TableLayout grid) {
    Map<Double, Hour> times = new TreeMap<>();
    List<Hour> hours = MainActivity.globals.getSqLite().getHours("");
    for (Hour hour : hours) {
        times.put(Double.parseDouble(hour.getStart().replace(":", ".")), hour);
    }//www  .j av  a2s  .c  o  m

    List hourList = Arrays.asList(times.values().toArray());
    int max = hourList.size() - 1;
    for (int i = 1; i <= grid.getChildCount() - 1; i++) {
        TableRow row = (TableRow) grid.getChildAt(i);
        TextView textView = (TextView) row.getChildAt(0);
        if ((i - 1) <= max) {
            Hour hour = (Hour) hourList.get(i - 1);
            textView.setText(String.format("%s%n%s", hour.getStart(), hour.getEnd()));
            textView.setTag(String.valueOf(hour.getID()));

            if (hour.isBreak()) {
                textView.setTextSize(14);
                textView.setText(textView.getText().toString().replace("\n", ":"));
                for (int j = 1; j <= row.getChildCount() - 1; j++) {
                    row.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    row.setBackgroundResource(R.drawable.tbl_border);
                }
            }
        } else {
            grid.getChildAt(i).setVisibility(View.GONE);
        }
    }
}

From source file:aws.apps.underthehood.Main.java

private void changeFontSize(TableLayout t, float fontSize) {
    for (int i = 0; i <= t.getChildCount() - 1; i++) {
        TableRow row = (TableRow) t.getChildAt(i);

        for (int j = 0; j <= row.getChildCount() - 1; j++) {
            View v = row.getChildAt(j);

            try {
                if (v.getClass() == Class.forName("android.widget.TextView")) {
                    TextView tv = (TextView) v;
                    if (i % 2 == 0) {
                    } else {
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
                    }/*w w  w . j  a v  a 2  s. c o m*/
                }
            } catch (Exception e) {
                Log.e(TAG, "^ changeFontSize: ");
            }
        }
    }
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Draw the grid./*w  w w . j av  a2 s . c  o m*/
 */
private void drawGrid() {
    //draw the grid based on project info
    thisMeasure = theproject.track(trackNum).measure(measureNum);
    TableLayout notedraw = (TableLayout) findViewById(R.id.notedraw);
    int notedrawlen = notedraw.getChildCount();

    //get note scale
    final float dscale = getApplicationContext().getResources().getDisplayMetrics().density;
    int notewidth = (int) (144 * dscale + 0.5f);
    int noteheight = (int) (75 * dscale + 0.5f);

    for (int x = 0; x < notedrawlen; x++) {
        TableRow noterow = (TableRow) notedraw.getChildAt(x);
        List<List<Integer>> rangelist = numNotesFromGuiSnap();
        for (int i = 0; i < rangelist.size(); i++) {
            ImageView note = new ImageView(getApplicationContext());
            note.setLayoutParams(new TableRow.LayoutParams(notewidth, noteheight));

            note.setTag(R.id.TAG_ROW, x);
            note.setTag(R.id.TAG_COLUMN, i);
            note.setTag(R.id.TAG_NOTE, notesdisplay[x]);

            note.setTag(R.id.TAG_GUISNAPRANGE, rangelist.get(i));

            note.setImageResource(R.drawable.measure_outline);
            if (filledNotesFromIntent.size() > 0) {
                for (int z = 0; z < filledNotesFromIntent.size(); z++) {
                    if ((filledNotesFromIntent.get(z)[0] == x) && (filledNotesFromIntent.get(z)[1] == i)) {
                        note.setImageResource(R.drawable.note_filled);
                    }
                }
            }

            note.setBackgroundColor(getResources().getColor(R.color.note_rest));

            note.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    paintNote(v);

                }
            });

            noterow.addView(note);
        }
    }
}