我创建了一个动态添加行的表格布局。 我有2个editTexts作为列。
我想我需要这样的东西:
If(tablerow exists below){
//do the focusing
}
else{
//add new row
//do the focusing
}
我使用函数 addView 添加行:
public void addView(Context context) {
int dpConv = (int) getResources().getDisplayMetrics().density;
i = i + 1;
try {
txt_itemName[i] = new EditText(context);
txt_itemName[i].setText("itName");
txt_itemName[i].requestFocus();
txt_qty[i] = new EditText(context);
txt_qty[i].setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
txt_qty[i].setImeOptions(EditorInfo.IME_ACTION_NEXT);
txt_qty[i].setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_NEXT){
txt_qty[i].clearFocus();
//Need to check conditions here
}
return false;
}
});
tb_row[i] = new TableRow(context);
tb_row[i].addView(txt_itemName[i]);
tb_row[i].addView(txt_qty[i]);
tb_lyt.addView(tb_row[i]);
答案 0 :(得分:0)
确定。如果你试试这个怎么样:
if(actionId == EditorInfo.IME_ACTION_NEXT){
txt_qty[i].clearFocus();
//Need to check conditions here
/* I'm assuming that:
You have the value of i
You add TableRows ONLY to your TableLayout
*/
if(tb_lyt.getChildCount() > (i+1)) {
//If a child exist below
//Do your focus setting
}
else {
//Add a new Row.
}
}