0

I have 2 editfields in my Custom Dialog which is called from ACtivity, among them 1 is of "trxtPassword" and other of "text" type. Keyboard doesn't appear in "text" type editbox, but just comes on "textPassword" edittext, and then doesn't go only.

I tried the following, but nothing works:

    InputMethodManager inputManager = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);   
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 

            //inputManager.hideSoftInputFromWindow(txt_username.getWindowToken(), 0);       
        //inputManager.hideSoftInputFromWindow(txt_password.getWindowToken(), 0);

If I make txt_password.setInputType(0); then others can see the password easily, so that can't be used.

What more can be doen to achieve the goal? I did to trap the onLostFocus on txt

txt_password.setOnFocusChangeListener(new View.OnFocusChangeListener() {            
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                 InputMethodManager inputManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);    
                 inputManager.hideSoftInputFromWindow(LoginDialog.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
            }
        }
    });

But unfortunately, once entered, if I click anywhere else or any checkbox, then also the focus is not lost from the txt_password field. That is only lost if I click another editText and then the onFocusChange event is fired and throws error and the application shuts down.

Any idea how to accomplish this?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Tvd
  • 4,463
  • 18
  • 79
  • 125
  • Just to clarify: Is your aim to make it so the keyboard does not appear? Or are you trying to dismiss the keyboard once you are finished with it? – HaemEternal Apr 14 '11 at 15:28
  • I am trying to dismisst he keyboard once I click anywhere outside the password text field. – Tvd Apr 14 '11 at 15:52
  • Is it not suitable for the user to click the "Done" button on the keyboard once they have entered the password, to dismiss the keyboard? (eg setImeOptions(EditorInfo.IME_ACTION_DONE);) – HaemEternal Apr 18 '11 at 08:28

1 Answers1

0

Use that to keep keyboard hidden on activity start

<activity
    android:name=".views.DrugstoreEditView"
    android:windowSoftInputMode="stateHidden"></activity>

And there is one usefull answer: How to hide soft keyboard on android after clicking outside EditText?

Community
  • 1
  • 1
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
  • Thanks dziobas, but that makes no difference. I still get the keyboard when focus is on password text field. – Tvd Apr 14 '11 at 15:22
  • Please clarify your question. Do you want to hide keyboard at all? – pawelzieba Apr 14 '11 at 15:32
  • I want to hide it completely only, but if at all user wants and it comes up, then once user clicks anywhere else outside the edittext, the keyboard should disappear. – Tvd Apr 14 '11 at 15:54