You can achieve this by using the Text Watcher
class and then set the focus on the next EditText
in the OnTextChanged()
method of the TextWatcher.
In your case, since you have two Edit Texts, say et1
and et2
. You can try out the following code:-
et1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,int before, int count)
{
// TODO Auto-generated method stub
if(et1.getText().toString().length()==size) //size as per your requirement
{
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
I have not checked out the code myself, but I hope this will help you solve your problem.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…