Java Code Examples for android.widget.TableRow#getChildCount()

The following examples show how to use android.widget.TableRow#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TicTacToeActivity.java    From bridgefy-android-samples with MIT License 6 votes vote down vote up
protected void initializeBoard() {
    size = 3;
    board = new int[size][size];
    mainBoard = findViewById(R.id.mainBoard);
    tv_turn = findViewById(R.id.turn);

    if (myTurn) {
        tv_turn.setText(String.format(getString(R.string.your_turn),
                String.valueOf(myTurnChar)));
    } else {
        tv_turn.setText(String.format(getString(R.string.their_turn),
                rival.getNick(), String.valueOf(flipChar(myTurnChar))));
    }

    resetBoard(null);

    for (int i = 0; i < mainBoard.getChildCount(); i++) {
        TableRow row = (TableRow) mainBoard.getChildAt(i);
        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);
            tv.setOnClickListener(MoveListener(i, j, tv));
            tv.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.black));
        }
    }
}
 
Example 2
Source File: MultiLineRadioGroup.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
private void arrangeButtons() {
    // iterates over each button and puts it in the right place
    for (int i = 0, len = mRadioButtons.size(); i < len; i++) {
        RadioButton radioButtonToPlace = mRadioButtons.get(i);
        int rowToInsert = (mMaxInRow != 0) ? i / mMaxInRow : 0;
        int columnToInsert = (mMaxInRow != 0) ? i % mMaxInRow : i;
        // gets the row to insert. if there is no row create one
        TableRow tableRowToInsert = (mTableLayout.getChildCount() <= rowToInsert)
                ? addTableRow() : (TableRow) mTableLayout.getChildAt(rowToInsert);
        int tableRowChildCount = tableRowToInsert.getChildCount();

        // if there is already a button in the position
        if (tableRowChildCount > columnToInsert) {
            RadioButton currentButton = (RadioButton) tableRowToInsert.getChildAt(columnToInsert);

            // insert the button just if the current button is different
            if (currentButton != radioButtonToPlace) {
                // removes the current button
                removeButtonFromParent(currentButton, tableRowToInsert);
                // removes the button to place from its current position
                removeButtonFromParent(radioButtonToPlace, (ViewGroup) radioButtonToPlace.getParent());
                // adds the button to the right place
                tableRowToInsert.addView(radioButtonToPlace, columnToInsert);
            }

            // if there isn't already a button in the position
        } else {
            // removes the button to place from its current position
            removeButtonFromParent(radioButtonToPlace, (ViewGroup) radioButtonToPlace.getParent());
            // adds the button to the right place
            tableRowToInsert.addView(radioButtonToPlace, columnToInsert);
        }
    }

    removeRedundancies();
}
 
Example 3
Source File: DisplayMnemonicActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            TextView me = (TextView) row.getChildAt(x * 2 + 1);
            me.setInputType(0);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                    }
                }
            });
            registerForContextMenu(me);

            mTextViews[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
Example 4
Source File: TicTacToeActivity.java    From bridgefy-android-samples with MIT License 5 votes vote down vote up
protected void disableInputs() {
    // disable play inputs
    for (int i = 0; i < mainBoard.getChildCount(); i++) {
        TableRow row = (TableRow) mainBoard.getChildAt(i);
        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);
            tv.setOnClickListener(null);
            tv.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray));
        }
    }
}
 
Example 5
Source File: ResultMatrixLayout.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private CustomEditText getCell(int row, int col)
{
    if (row < getChildCount())
    {
        final TableRow tr = (TableRow) getChildAt(row);
        if (tr != null && col < tr.getChildCount())
        {
            return (CustomEditText) tr.getChildAt(col);
        }
    }
    return null;
}
 
Example 6
Source File: RadioButtonGroupTableLayout.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 *
 * @param tr -
 */
private void setChildrenOnClickListener( TableRow tr ){
    final int c = tr.getChildCount();
    for ( int i = 0; i < c; i++ ){
        View v = tr.getChildAt(i);
        if ( v instanceof RadioButton ) v.setOnClickListener(this);
    }
}
 
Example 7
Source File: MultiLineRadioGroup.java    From MultiLineRadioGroup with MIT License 5 votes vote down vote up
private void arrangeButtons() {
    // iterates over each button and puts it in the right place
    for (int i = 0, len = mRadioButtons.size(); i < len; i++) {
        RadioButton radioButtonToPlace = mRadioButtons.get(i);
        int rowToInsert = (mMaxInRow != 0) ? i / mMaxInRow : 0;
        int columnToInsert = (mMaxInRow != 0) ? i % mMaxInRow : i;
        // gets the row to insert. if there is no row create one
        TableRow tableRowToInsert = (mTableLayout.getChildCount() <= rowToInsert)
                ? addTableRow() : (TableRow) mTableLayout.getChildAt(rowToInsert);
        int tableRowChildCount = tableRowToInsert.getChildCount();

        // if there is already a button in the position
        if (tableRowChildCount > columnToInsert) {
            RadioButton currentButton = (RadioButton) tableRowToInsert.getChildAt(columnToInsert);

            // insert the button just if the current button is different
            if (currentButton != radioButtonToPlace) {
                // removes the current button
                removeButtonFromParent(currentButton, tableRowToInsert);
                // removes the button to place from its current position
                removeButtonFromParent(radioButtonToPlace, (ViewGroup) radioButtonToPlace.getParent());
                // adds the button to the right place
                tableRowToInsert.addView(radioButtonToPlace, columnToInsert);
            }

            // if there isn't already a button in the position
        } else {
            // removes the button to place from its current position
            removeButtonFromParent(radioButtonToPlace, (ViewGroup) radioButtonToPlace.getParent());
            // adds the button to the right place
            tableRowToInsert.addView(radioButtonToPlace, columnToInsert);
        }
    }

    removeRedundancies();
}
 
Example 8
Source File: KanjiSearchRadicalActivity.java    From aedict with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes currently selected radicals.
 */
private String getRadicals() {
	final StringBuilder sb = new StringBuilder();
	final TableLayout v = (TableLayout) findViewById(R.id.kanjisearchRadicals);
	for (int i = 0; i < v.getChildCount(); i++) {
		final TableRow tr = (TableRow) v.getChildAt(i);
		for (int j = 0; j < tr.getChildCount(); j++) {
			final PushButtonListener pbl = (PushButtonListener) tr.getChildAt(j).getTag();
			if (pbl != null && pbl.isPushed()) {
				sb.append(pbl.radical);
			}
		}
	}
	return sb.toString();
}
 
Example 9
Source File: QuestionFragment.java    From android-galaxyzoo with GNU General Public License v3.0 5 votes vote down vote up
private static void insertButtonInRow(final Context context, final TableRow row, final View button) {
    final TableRow.LayoutParams params =
            new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 1f /* weight */);
    //Use as little padding as possible at the left and right because the button
    //will usually get extra space from the TableLayout anyway,
    //but we want to avoid ugly line-breaks when the text is long (such as in translations).

    //Space around the inside of the buttons:
    //When we use smaller dp values, there seems to be no padding at the sides at all,
    //probably because the edges of the button are actually dependent on the standard background
    //image for buttons.
    //2 * standard_margin is nicer, but there is usually more, because the buttons expand
    //and a too-small margin is better than splitting a word across lines.
    final int padding = UiUtils.getPxForDpResource(context, R.dimen.small_margin);
    button.setPadding(padding, button.getPaddingTop(), padding, padding);

    if(row.getChildCount() > 0) {
        //Space between the buttons:
        final int margin = UiUtils.getPxForDpResource(context, R.dimen.tiny_gap);
        params.setMargins(margin, 0, 0, 0);
        // When using the standard background drawable (not our custom background color
        // which replaces it) This reduces the space caused by the standard background drawable,
        // but negative margins are unmaintainable voodoo:
        // params.setMargins(-4, 0, -4, 0);
    }

    row.addView(button, params);
}
 
Example 10
Source File: MultiLineRadioGroup.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
private void removeRedundancies() {
    // the number of rows to fit the buttons
    int rows;
    if (mRadioButtons.size() == 0)
        rows = 0;
    else if (mMaxInRow == 0)
        rows = 1;
    else
        rows = (mRadioButtons.size() - 1) / mMaxInRow + 1;

    int tableChildCount = mTableLayout.getChildCount();
    // if there are redundant rows remove them
    if (tableChildCount > rows)
        mTableLayout.removeViews(rows, tableChildCount - rows);

    tableChildCount = mTableLayout.getChildCount();
    int maxInRow = (mMaxInRow != 0) ? mMaxInRow : mRadioButtons.size();

    // iterates over the rows
    for (int i = 0; i < tableChildCount; i++) {
        TableRow tableRow = (TableRow) mTableLayout.getChildAt(i);
        int tableRowChildCount = tableRow.getChildCount();

        int startIndexToRemove;
        int count;

        // if it is the last row removes all redundancies after the last button in the list
        if (i == tableChildCount - 1) {
            startIndexToRemove = (mRadioButtons.size() - 1) % maxInRow + 1;
            count = tableRowChildCount - startIndexToRemove;

            // if it is not the last row removes all the buttons after maxInRow position
        } else {
            startIndexToRemove = maxInRow;
            count = tableRowChildCount - maxInRow;
        }

        if (count > 0)
            tableRow.removeViews(startIndexToRemove, count);
    }
}
 
Example 11
Source File: MnemonicActivity.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            MultiAutoCompleteTextView me = (MultiAutoCompleteTextView) row.getChildAt(x * 2 + 1);
            me.setAdapter(mWordsAdapter);
            me.setThreshold(3);
            me.setTokenizer(mTokenizer);
            me.setOnEditorActionListener(this);
            me.setOnKeyListener(this);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                        return;
                    }
                    final boolean isInvalid = markInvalidWord(s);
                    if (!isInvalid && (s.length() > 3)) {
                        if (!enableLogin())
                            nextFocus();
                    }
                    enableLogin();
                }
            });
            me.setOnFocusChangeListener((View v, boolean hasFocus) -> {
                if (!hasFocus && v instanceof EditText) {
                    final Editable e = ((EditText)v).getEditableText();
                    final String word = e.toString();
                    if (!MnemonicHelper.mWords.contains(word)) {
                        e.setSpan(new StrikethroughSpan(), 0, word.length(), 0);
                    }
                }
            });
            registerForContextMenu(me);

            mWordEditTexts[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
Example 12
Source File: ResultMatrixLayout.java    From microMathematics with GNU General Public License v3.0 4 votes vote down vote up
public void resize(int rows, int cols, int cellLayoutId)
{
    if (rowsNumber == rows && colsNumber == cols)
    {
        return;
    }
    rowsNumber = rows;
    colsNumber = cols;

    removeAllViews();
    fields.clear();

    final TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);

    final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);

    for (int row = 0; row < rowsNumber; row++)
    {
        final TableRow tableRow = new TableRow(getContext());
        tableRow.setLayoutParams(tableParams); // TableLayout is the parent view
        addView(tableRow);

        for (int col = 0; col < colsNumber; col++)
        {
            inflater.inflate(cellLayoutId, tableRow);
        }

        if (tableRow.getChildCount() > 0)
        {
            tableRow.setBaselineAligned(true);
            tableRow.setBaselineAlignedChildIndex(0);
        }

        for (int col = 0; col < tableRow.getChildCount(); col++)
        {
            final CustomEditText c = (CustomEditText) tableRow.getChildAt(col);
            if (c != null)
            {
                c.setId(IdGenerator.generateId());
                c.setTag(new ElementTag(row, col, fields.size()));
                fields.add(c);
            }
        }
    }

    setPadding(0, 0, 0, 0);
    setBaselineAligned(true);
    setBaselineAlignedChildIndex(rowsNumber > 1 ? rowsNumber / 2 : 0);
}
 
Example 13
Source File: MyDialog.java    From ExpandableRecyclerView with Apache License 2.0 4 votes vote down vote up
private ArrayList<String> checkInput(View table) {
    if (!(table instanceof TableLayout)) return null;
    ArrayList<String> result = new ArrayList<>();
    TableLayout tableLayout = (TableLayout) table;
    final int childCount = tableLayout.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View tableChild = tableLayout.getChildAt(i);
        if (tableChild instanceof TableRow) {
            TableRow tableRow = (TableRow) tableChild;
            final int count = tableRow.getChildCount();
            for (int j = 0; j < count; j++) {
                View childView = tableRow.getChildAt(j);
                if (!(childView instanceof EditText)) continue;
                EditText editText = (EditText) childView;
                String type = editText.getHint().toString();
                String method = (String) editText.getTag();
                String input = editText.getText().toString().trim();
                if (TextUtils.isEmpty(input)) continue;
                String[] methods = input.split("\n");
                for (String m : methods) {
                    String methodType = "";
                    String[] args = m.split(",");
                    if (type.equals(PARENT_TYPE)) {
                        if (args.length == 1) {
                            methodType = ITEM_OPERATE_TYPE;
                        } else if (args.length == 2) {
                            methodType = ITEM_RANGE_OPERATE_TYPE;
                        }
                    } else if (type.equals(CHILD_TYPE)) {
                        if (args.length == 2) {
                            methodType = ITEM_OPERATE_TYPE;
                        } else if (args.length == 3) {
                            methodType = ITEM_RANGE_OPERATE_TYPE;
                        }
                    } else if (type.equals(MOVE_PARENT_TYPE)) {
                        if (args.length == 2) {
                            methodType = ITEM_OPERATE_TYPE;
                        }
                    } else if (type.equals(MOVE_CHILD_TYPE)) {
                        if (args.length == 4) {
                            methodType = ITEM_OPERATE_TYPE;
                        }
                    }
                    String methodName = String.format(method, methodType);
                    String ma = String.format(getString(R.string.methodAndArgs), methodName, m);
                    result.add(ma);
                }
            }
        }
    }
    Logger.e(TAG, "requestList=" + result.toString());
    return result;
}
 
Example 14
Source File: MultiLineRadioGroup.java    From MultiLineRadioGroup with MIT License 4 votes vote down vote up
private void removeRedundancies() {
    // the number of rows to fit the buttons
    int rows;
    if (mRadioButtons.size() == 0)
        rows = 0;
    else if (mMaxInRow == 0)
        rows = 1;
    else
        rows = (mRadioButtons.size() - 1) / mMaxInRow + 1;

    int tableChildCount = mTableLayout.getChildCount();
    // if there are redundant rows remove them
    if (tableChildCount > rows)
        mTableLayout.removeViews(rows, tableChildCount - rows);

    tableChildCount = mTableLayout.getChildCount();
    int maxInRow = (mMaxInRow != 0) ? mMaxInRow : mRadioButtons.size();

    // iterates over the rows
    for (int i = 0; i < tableChildCount; i++) {
        TableRow tableRow = (TableRow) mTableLayout.getChildAt(i);
        int tableRowChildCount = tableRow.getChildCount();

        int startIndexToRemove;
        int count;

        // if it is the last row removes all redundancies after the last button in the list
        if (i == tableChildCount - 1) {
            startIndexToRemove = (mRadioButtons.size() - 1) % maxInRow + 1;
            count = tableRowChildCount - startIndexToRemove;

            // if it is not the last row removes all the buttons after maxInRow position
        } else {
            startIndexToRemove = maxInRow;
            count = tableRowChildCount - maxInRow;
        }

        if (count > 0)
            tableRow.removeViews(startIndexToRemove, count);
    }
}