Android: How to open keyboard for editing EditText when click button?

Thanks guys for your help 🙂 I used all suggestions that you gave me, searched and tested a lot of other scripts and finally my code is working 🙂

Here is my final code:

InputEditText = (EditText) findViewById(;

public void InputData() {

        /* Keyboard Button Action */
        KeyboardButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Log.v(TAG, "On Keyboard Button click event!");


                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(InputEditText, InputMethodManager.SHOW_FORCED);




It may be useful for someone 🙂
Thank you!

The design you’ve described isn’t recommended. You’re violating the focusable attribute’s purpose which is not to control whether the user can alter the text in a EditText component.

If you plan to provide an alternative input method because the use case seems to require this (e.g. you allow only a certain set of symbols in the editable text field) then you should probably disable text editing altogether for the time the user isn’t allowed to change the value of the field.

Declare your editable field:

    android:ems="10" />

notice that its focusable attribute is left with the default value. That’s ok, we’ll handle that later. Declare a button which will start editing process:

    android:text="Start editing" />

Now, in your Activity declare:

private EditText editText2;
private KeyListener originalKeyListener;
private Button buttonShowIme;

And in onCreate() do this:

protected void onCreate(Bundle savedInstanceState) {

    // Find out our editable field.
    editText2 = (EditText)findViewById(;
    // Save its key listener which makes it editable.
    originalKeyListener = editText2.getKeyListener();
    // Set it to null - this will make the field non-editable

    // Find the button which will start editing process.
    buttonShowIme = (Button)findViewById(;
    // Attach an on-click listener.
    buttonShowIme.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Restore key listener - this will make the field editable again.
            // Focus the field.
            // Show soft keyboard for the user to enter the value.
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);

    // We also want to disable editing when the user exits the field.
    // This will make the button the only non-programmatic way of editing it.
    editText2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            // If it loses focus...
            if (!hasFocus) {
                // Hide soft keyboard.
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editText2.getWindowToken(), 0);
                // Make it non-editable again.

I hope the code with all the comments is self-explanatory. Tested on APIs 8 and 17.

Try this :

        final EditText myedit2 = (EditText) findViewById(;

        Button btsmall = (Button) findViewById(;
        btsmall.setOnClickListener(new OnClickListener() {              
            public void onClick(View arg0) {