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

The following examples show how to use android.widget.TableRow#getChildAt() . 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: TicTacToeActivity.java    From bridgefy-android-samples with MIT License 6 votes vote down vote up
protected void resetBoard(int[][] board) {
    for (int i = 0; i < size; i++) {
        TableRow row = (TableRow) mainBoard.getChildAt(i);
        for (int j = 0; j < size; j++) {
            char c = board != null ? (char) board[i][j] : 0;
            this.board[i][j] = c;

            TextView tv = (TextView) row.getChildAt(j);
            switch (c) {
                case 'X':
                    tv.setText(R.string.X);
                    break;
                case 'O':
                    tv.setText(R.string.O);
                    break;
                default:
                    tv.setText(R.string.none);
                    break;
            }
        }
    }
}
 
Example 3
Source File: TimetableView.java    From TimetableView with Apache License 2.0 5 votes vote down vote up
public void setHeaderHighlight(int idx) {
    if(idx < 0)return;
    TableRow row = (TableRow) tableHeader.getChildAt(0);
    View element = row.getChildAt(idx);
    if(highlightMode == HighlightMode.COLOR) {
        TextView tx = (TextView)element;
        tx.setTextColor(Color.parseColor("#FFFFFF"));
        tx.setBackgroundColor(headerHighlightColor);
        tx.setTypeface(null, Typeface.BOLD);
        tx.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_HEADER_HIGHLIGHT_FONT_SIZE_DP);
    }
    else if(highlightMode == HighlightMode.IMAGE){
        RelativeLayout outer = new RelativeLayout(context);
        outer.setLayoutParams(createTableRowParam(cellHeight));
        ImageView iv = new ImageView(context);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(headerHighlightImageSize,headerHighlightImageSize);
        params.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
        iv.setLayoutParams(params);
        iv.setScaleType(ImageView.ScaleType.CENTER_CROP);

        row.removeViewAt(idx);
        outer.addView(iv);
        row.addView(outer,idx);

        if(headerHighlightImage != null) {
            iv.setImageDrawable(headerHighlightImage);
        }

    }
}
 
Example 4
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 5
Source File: FilterConfig.java    From personaldnsfilter with GNU General Public License v2.0 5 votes vote down vote up
private View[] getContentCells(TableRow row) {

		View[] result = new View[5];
		for (int i = 0; i < 5; i++)
			result[i] = row.getChildAt(i);

		result[2] = ((ViewGroup) result[2]).getChildAt(0); // element 1 is a scrollview with nested TextView
		result[3] = ((ViewGroup) result[3]).getChildAt(0); // element 2 is a scrollview with nested TextView

		return result;
	}
 
Example 6
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 7
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 8
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 9
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 10
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 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: ChangeRulesDialogFragment.java    From GameOfLife with MIT License 4 votes vote down vote up
protected void initCheckBox(final int i, TableRow checkBoxes, Set<Integer> nbCounts) {
    final CheckBox checkBox = (CheckBox) checkBoxes.getChildAt(i);
    checkBox.setChecked(rule != null && nbCounts.contains(i));
    setOnClickListener(checkBox);
}