0

I want to switch between two EditText views when KEYCODE_DEL button is pressed.

My code works, it indeed focuses previous EditText, but when it does that, the keyboard vanishes, and cursor is located before the actual text in that EditText.

To make it more vivid, when the focus switches, the EditText looks like this:

|23 where | is the cursor position and keyboard is hidden.

Here is my code:

if(event.getKeyCode() == KeyEvent.KEYCODE_DEL){
        super.dispatchKeyEvent(event);
        focusPreviousET();
        return true;
    }
else{
    super.dispatchKeyEvent(event);
    check();
    return true;
 }

private void focusPreviousET() {

    String sId = getId(getCurrentFocus());

    Identification id = new Identification(sId);

    etX = getETFromResource(id);

    if(isEmpty(etX)){
        etX.setEnabled(false);
        id.previousId();
        etX = getETFromResource(id);
        etX.requestFocus();
    }
}
public void check(){
       etX  = (EditText) getCurrentFocus();
    if(etX.getText().toString().length()==2){
        focusNextFreeET();
    }
}

Also check() method doesn't work, and i don't know why... Method focusNextFreeET() works in other cases, but not here.

Any suggestions?

EDIT

Forgot to mention, cursor is actually located at the end when the EditText is filled with numbers like 22,31,10, and cursor is located at the beggining when the number has a 0 in front of it, like 01,02, etc... In both cases, keyboard is hidden.

Pavle Pavlov
  • 189
  • 2
  • 13

1 Answers1

0

Use these lines after focusing next item to open a keyboard

InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
Neal Ahluvalia
  • 1,538
  • 1
  • 10
  • 20