WHAT I HAVE
I created a table layout where the rows are dynamically added.
I have 2 editTexts as columns.
WHAT I WANT
- If a table row’s second editText is focused and enter is pressed, then:
- If a table row exists below, focus should be set to it’s edittext.
- If NO table row exists below, table row should be added and then focus set.
I think I need something like:
If(tablerow exists below){
//do the focusing
}
else{
//add new row
//do the focusing
}
I used a function addView to add the rows :
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]);
Ok. what about if you try this: