Question

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);}

}

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top