2

hi I have two edit text boxes in my screen.i am enabling landscape support only when the edit text got focus. And disabling the same when user press done button on the soft keyboard.user enter the value in the first edit text and press next button.Then enter value in second edit text and press "done " button.One thing i want to do is need to force lose the focus from second edittext.i have tried clearFocus() and button.requestFocus() but not helpfull.given below is my code snippet.

@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEND
            || actionId == EditorInfo.IME_ACTION_DONE
            || actionId == EditorInfo.IME_ACTION_GO
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

    ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
     InputMethodManager imm = (InputMethodManager) context
               .getSystemService(Context.INPUT_METHOD_SERVICE);
     if (imm != null) 
     imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

     return true;
    }
    return false;
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if(hasFocus)
    ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}

After clicking "done" button if the user click on second edit text the control is not coming to onFocusChange event. Please help me

andro-girl
  • 7,989
  • 22
  • 71
  • 94

2 Answers2

2

Follow the accepted answer to This question. When you finish processing in OnEditorAction method just set focus to that dummy layout

Community
  • 1
  • 1
Anton
  • 4,395
  • 7
  • 32
  • 46
0

If I understand correctly, you want to close the keyboard when the "done" button is pressed? If so, try adding this line to its onClickListener:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
IncrediApp
  • 10,303
  • 2
  • 33
  • 24