下面列出了android.widget.TableLayout#indexOfChild ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CustomEditText setFocusToSpecific(CustomEditText customEditText) {
TableRow tableRow = (TableRow) customEditText.getParent();
TableLayout tableLayout = (TableLayout) tableRow.getParent();
int indexOnTable = tableLayout.indexOfChild(tableRow);
if (indexOnTable == 0) {
//what if index is 0, get the previous on edittext
}
TableRow prevRow = (TableRow) tableLayout.getChildAt(indexOnTable - 1);
if (prevRow != null) {
CustomEditText editText = (CustomEditText) tableRow.findViewById(R.id.txtText);
if (editText.requestFocus()) {
editText.setSelection(editText.getText().length());
}
return editText;
}
return null;
}
@Override
public void onClick(View v) {
//get index of the button as seen from the container
TableRow row = (TableRow) v.getParent();
TableLayout table = (TableLayout) row.getParent();
int index = table.indexOfChild(row) * COLUMNS + row.indexOfChild(v);
loadGameText(index);
}
public void validateAndRemoveLisNode(View view, EditorControl contentType) {
/*
*
* If the person was on an active ul|li, move him to the previous node
*
*/
TableRow _row = (TableRow) view.getParent();
TableLayout _table = (TableLayout) _row.getParent();
int indexOnList = _table.indexOfChild(_row);
_table.removeView(_row);
if (indexOnList > 0) {
/**
* check if the index of the deleted row is <0, if so, move the focus to the previous li
*/
TableRow focusrow = (TableRow) _table.getChildAt(indexOnList - 1);
EditText text = (EditText) focusrow.findViewById(R.id.txtText);
/**
* Rearrange the nodes
*/
if (contentType.Type == EditorType.OL_LI) {
rearrangeColumns(_table);
}
if (text.requestFocus()) {
text.setSelection(text.getText().length());
}
} else {
/**
* The removed row was first on the list. delete the list, and set the focus to previous element on the editor
*/
editorCore.removeParent(_table);
}
}
public int getIndexOnEditorByEditText(CustomEditText customEditText) {
TableRow tableRow = (TableRow) customEditText.getParent();
TableLayout tableLayout = (TableLayout) tableRow.getParent();
int indexOnTable = tableLayout.indexOfChild(tableRow);
return indexOnTable;
}