下面列出了android.widget.TableLayout#getChildCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@NonNull
private TableRow ensureRow(@NonNull TableLayout layout, int row) {
final int count = layout.getChildCount();
// fill the requested views until we have added the `row` one
if (row >= count) {
final Context context = layout.getContext();
int diff = row - count + 1;
while (diff > 0) {
layout.addView(new TableRow(context));
diff -= 1;
}
}
// return requested child (here it always should be the last one)
return (TableRow) layout.getChildAt(row);
}
@Override
public Node getContent(View view) {
Node node = getNodeInstance(view);
node.childs = new ArrayList<>();
TableLayout table = (TableLayout) view;
int _rowCount = table.getChildCount();
for (int j = 0; j < _rowCount; j++) {
View row = table.getChildAt(j);
Node node1 = getNodeInstance(row);
EditText li = row.findViewById(R.id.txtText);
EditorControl liTag = (EditorControl) li.getTag();
node1.contentStyles = liTag.editorTextStyles;
node1.content.add(Html.toHtml(li.getText()));
node1.textSettings = liTag.textSettings;
node1.content.add(Html.toHtml(li.getText()));
node.childs.add(node1);
}
return node;
}
public void convertListToNormalText(TableLayout _table, int startIndex) {
int tableChildCount = _table.getChildCount();
for (int i = startIndex; i < tableChildCount; i++) {
View _childRow = _table.getChildAt(i);
_table.removeView(_childRow);
String text = getTextFromListItem(_childRow);
int Index = editorCore.getParentView().indexOfChild(_table);
componentsWrapper.getInputExtensions().insertEditText(Index + 1, "", text);
i -= 1;
tableChildCount -= 1;
}
//if item is the last in the table, remove the table from parent
if (_table.getChildCount() == 0) {
editorCore.getParentView().removeView(_table);
}
}
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);
}
layoutAnswers.addView(row, params);
return row;
}
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;
}
}
}
public void convertListToOrdered(TableLayout _table) {
EditorControl type = editorCore.createTag(EditorType.ol);
_table.setTag(type);
for (int i = 0; i < _table.getChildCount(); i++) {
View _childRow = _table.getChildAt(i);
CustomEditText editText = (CustomEditText) _childRow.findViewById(R.id.txtText);
editText.setTag(editorCore.createTag(EditorType.OL_LI));
_childRow.setTag(editorCore.createTag(EditorType.OL_LI));
TextView _bullet = (TextView) _childRow.findViewById(R.id.lblOrder);
_bullet.setText(String.valueOf(i + 1) + ".");
}
}
public void convertListToUnordered(TableLayout _table) {
EditorControl type = editorCore.createTag(EditorType.ul);
_table.setTag(type);
for (int i = 0; i < _table.getChildCount(); i++) {
View _childRow = _table.getChildAt(i);
CustomEditText _EditText = (CustomEditText) _childRow.findViewById(R.id.txtText);
_EditText.setTag(editorCore.createTag(EditorType.UL_LI));
_childRow.setTag(editorCore.createTag(EditorType.UL_LI));
TextView _bullet = (TextView) _childRow.findViewById(R.id.lblOrder);
_bullet.setText("•");
}
}
private void rearrangeColumns(TableLayout _table) {
//TODO, make sure that if OL, all the items are ordered numerically
for (int i = 0; i < _table.getChildCount(); i++) {
TableRow tableRow = (TableRow) _table.getChildAt(i);
TextView _bullet = (TextView) tableRow.findViewById(R.id.lblOrder);
_bullet.setText(String.valueOf(i + 1) + ".");
}
}
public void setFocusToList(View view, int position) {
TableLayout tableLayout = (TableLayout) view;
int count = tableLayout.getChildCount();
if (tableLayout.getChildCount() > 0) {
TableRow tableRow = (TableRow) tableLayout.getChildAt(position == POSITION_START ? 0 : count - 1);
if (tableRow != null) {
EditText editText = (EditText) tableRow.findViewById(R.id.txtText);
if (editText.requestFocus()) {
editText.setSelection(editText.getText().length());
}
}
}
}
private void cleanTable(TableLayout table) {
int childCount = table.getChildCount();
// Remove all rows except the first one
if (childCount > 1) {
table.removeViews(1, childCount - 1);
}
}
/**
* 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();
}
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;
}
}
}
private void setProperties(ArrayList<FileMeta> properties) {
this.properties = properties;
if (properties == null) {
propertiesCard.setVisibility(View.GONE);
return;
}
if (propertiesCard.getVisibility() != View.VISIBLE) {
propertiesCard.setVisibility(View.VISIBLE);
}
Analytics.EventBuilder analytics = Analytics.newEvent("busybox properties");
for (FileMeta property : properties) {
analytics.put(property.label, property.value);
}
analytics.log();
TableLayout tableLayout = getViewById(R.id.table_properties);
if (tableLayout.getChildCount() > 0) {
tableLayout.removeAllViews();
}
int width = ResUtils.dpToPx(128);
int left = ResUtils.dpToPx(16);
int top = ResUtils.dpToPx(6);
int bottom = ResUtils.dpToPx(6);
int i = 0;
for (FileMeta meta : properties) {
TableRow tableRow = new TableRow(getActivity());
TextView nameText = new TextView(getActivity());
TextView valueText = new TextView(getActivity());
if (i % 2 == 0) {
tableRow.setBackgroundColor(0x0D000000);
} else {
tableRow.setBackgroundColor(Color.TRANSPARENT);
}
nameText.setLayoutParams(new TableRow.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
nameText.setPadding(left, top, 0, bottom);
nameText.setAllCaps(true);
nameText.setTypeface(Typeface.DEFAULT_BOLD);
nameText.setText(meta.name);
valueText.setPadding(left, top, 0, bottom);
valueText.setText(meta.value);
tableRow.addView(nameText);
tableRow.addView(valueText);
tableLayout.addView(tableRow);
i++;
}
}
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;
}