Zapnologica
Zapnologica

Reputation: 22556

Make android keyboard auto popup in dialog

I have a dialogue which prompts a user to enter in a 4 digit pin.

I would like for the keyboard to automatically be displayed when this dialog fragment popup is shown,

I have tried the following but I have not come right

    <EditText
    android:id="@+id/entercode_dialog_editText_code"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:ems="10"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center_horizontal"
    android:inputType="numberPassword" >

    <requestFocus />
</EditText>

Upvotes: 0

Views: 671

Answers (3)

Danang Kukuh
Danang Kukuh

Reputation: 57

To appear the soft keyboard , you can use

 EditText yourEditText= (EditText) findViewById(R.id.et);  
 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
 imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

To close it you can use

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

Hope Can Help You

Upvotes: 0

Kalpesh Lakhani
Kalpesh Lakhani

Reputation: 993

Try This for Showing KeyBoard:

InputMethodManager imm = (InputMethodManager)getactivity().
                             getSystemService(Context.INPUT_METHOD_SERVICE);

solutiuon1:

if(imm != null){
    imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}

solution2:

if(imm != null){
imm.showSoftInput(ed, 0);
} 

where ed is your edittext


one more solution (not tried yet) after inializing dialog

getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Upvotes: 2

Laxmeena
Laxmeena

Reputation: 790

Use this:-

myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

Upvotes: 1

Related Questions