Ankata
Ankata

Reputation: 101

Can not open soft keyboard in EditText control

I want to create 1 edit text with the below condition: - User can not focus on this control in normal. - When user click on this control, soft-keyborad is displayed and user can input into this control - When user press enter on this soft-keyborad or back on device, it is closed and back to normal view with control is not focus.

I tried the below code but not work :( When starting, control is not focus: ok

When click on control, at the first click, control is focus but not display soft-keyborad

In the second click, display soft-keyborad

Upvotes: 0

Views: 1641

Answers (3)

5hssba
5hssba

Reputation: 8079

  1. In your xml which has edittext put these values for the layout node

     android:focusable="true" 
    android:focusableInTouchMode="true"
    

    and dont put any focusable or focusable in touch mode attributes for your edittext..

  2. Then in your code in onKey method remove thse lines..

     txtSearch.setFocusable(false);
       txtSearch.setFocusableInTouchMode(false);
    

    and put

     txtSearch.clearFocus();
    
  3. And You should override this method

    onBackPressed() 
    

    like this..

     @Override
      public void onBackPressed() {
     txtSearch.clearFocus();
     //hide the soft keyboard..
    
      }
    

Upvotes: 1

Zaz Gmy
Zaz Gmy

Reputation: 4356

use this in onClick()

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

to close the keypad use

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

Upvotes: 0

Its not blank
Its not blank

Reputation: 3095

try commenting

hidekeyboard(v);

and the changes that Alex Lockwood suggested.

Upvotes: 0

Related Questions