I have a few EditText that are dynamically generated. I want to change the focus to the next EditText once the required length is reached. i have put all the Edit Texts on an ArrayList and am trying to add an event to shift the focus to next one but nothing seems to be working. i cannot call the editText field by id because they are dynamically generated.
final ArrayList<EditText> myEt = new ArrayList<EditText>();
for(int a = 0; a < g2.getChildCount(); a++){//g2 is parent layout
if(g2.getChildAt(a) instanceof EditText);
myEt.add((EditText) g2.getChildAt(a));
}
for(int b =0; b>myEt.size()-1; ++b){
final EditText e;
final EditText e1;
e = (EditText) myEt.get(b);
e1 = (EditText) myEt.get(b+1);
e.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(e.getText().toString().length() > 4){
e.clearFocus();
e1.requestFocus();
}
return false;
}
});
}