In my app I have 3 editTexts
like this
____ ____ ____
Lets call them et1, et2, et3
from left to right
Now when the user is on et3
and he presses back on the keyboard (provided et3
is empty) I want the focus to shift to the nearest editText on the left which is et2
here. I have been trying for quite some time but couldn't find any solution to this problem which looked trivial to me at first.
Problem is that the only way I found so far to capture the backpress event of the keyboard is by making a custom editText as said in this answer, code of which is below.
public class EditTextV2 extends EditText
{
public EditTextV2( Context context )
{
super( context );
}
public EditTextV2( Context context, AttributeSet attribute_set )
{
super( context, attribute_set );
}
public EditTextV2( Context context, AttributeSet attribute_set, int def_style_attribute )
{
super( context, attribute_set, def_style_attribute );
}
@Override
public boolean onKeyPreIme( int key_code, KeyEvent event )
{
if ( event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP )
this.clearFocus();
return super.onKeyPreIme( key_code, event );
}
}
Using this way I may be able to clear the focus from the current editText
but how do I shift the focus to left editText
? The default behavior on android is that it move focus to the left most editText
i.e et1
in my case. Is there a way? Or is there another way? Any help would be appreciated. Thanks!