1

I have a problem with the keyboard. I've research all the "Stackoverflow", I've tested million of different methods. And still cannot to make the keyboard hidden, when the "Dialog" shows up. May be anybody has a 10000% working solution?

public class ConfirmDialog extends DialogPreference implements OnClickListener{

public ConfirmDialog(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub

    setPositiveButtonText(R.string.b_ok);
    setNegativeButtonText(R.string.b_cancel);
}

protected View onCreateDialogView(){

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View createdv = inflater.inflate(R.layout.confirm_dialog, null);

          //Here I've tried to hide a keyboard!!!!!!!!!!!!!!
    ((EditText) createdv.findViewById(R.id.confirm_name)).setOnFocusChangeListener(new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus)
            {
                   getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
            }
            // TODO Auto-generated method stub

        }
    });

    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);}

}

user922907
  • 539
  • 2
  • 8
  • 18

2 Answers2

2

Solved… In XML document right in front of EditText tag I've added…

<LinearLayout android:focusable="true"
            android:focusableInTouchMode="true" 
            android:layout_width="0px"
            android:layout_height="0px" />

I've read it here.

user922907
  • 539
  • 2
  • 8
  • 18
  • well that makes it easy. – CrandellWS Feb 26 '16 at 14:47
  • @user922907, Thank you. Extremely clever and very simple. None of he 'regular' solutions here on SO (all variations of your original code sample above) seem to work for a DialogPreference layout. – Anne Gunn Jul 05 '16 at 17:24
1

this how i implement it in my project this method take the view like edittext and hide the soft keyboard

private void hidesoftKeyboard(View v) {

    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

}

feed me back

mohammed momn
  • 3,230
  • 1
  • 20
  • 16