0

I have an layout with 5 Edit texts and 3 radio buttons and two button..After 5 edit texts I have 3 radio buttons and after that 2 buttons. After enter the text in fifth edit text I am unable to see radio buttons and normal buttons due to soft keyboard. How can I disable that soft keyboard after enter the fifth edit text? Can any one please help me out of this problem...

yamuna
  • 41
  • 1
  • 9
  • Ideally you shouldn't be doing it because it is up to the user to determine whether he is done editing.So shouldn't the user being the one closing the keyboard? – Droidekas Jan 02 '15 at 10:31

5 Answers5

0

Try the following code snippet to hide/close the soft keyboard

getWindow().setSoftInputMode(
     WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
BeingMIAkashs
  • 1,375
  • 11
  • 18
  • It hides soft keyboard after enter the text in last edit tetx? I applied InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(country.getWindowToken(), 0); code for last edit text value – yamuna Jan 02 '15 at 10:05
0
public void hideKeyBord(View view) {
    if (view != null) {
        if (keyBoardHide == null) {
            keyBoardHide = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        }
        if (keyBoardHide != null && keyBoardHide.isActive()) {
            // to hide keyboard
            keyBoardHide.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
}
0
        InputMethodManager inputManager = (InputMethodManager)
                getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

        inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
chain
  • 649
  • 10
  • 22
0

Simply use :

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

whenever you want to hide the soft keyboard.

In your case : Let your fifth EditText be et.. Then use :

if(!et.toString().equals(null)){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}


OR

You can detect if the fifth EditText was focused or not and then acting accordingly(i.e Hiding the keyboard using the method above if the EditText was focused) by following the link below:
How can I detect focused EditText in android?

OR

Detect Done key event on soft keyboard :
The keyboard would automatically close when DONE button is pressed. But if you want to perform customs actions when DONE button is pressed, refer below :

        et= (EditText) findViewById(R.id.edit_text); 

        et.setOnEditorActionListener(new OnEditorActionListener() { 
            @Override 
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // do your stuff here 
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                } 
                return false; 
            } 

    }); 

Hope this Helps!

Community
  • 1
  • 1
gsanskar
  • 673
  • 5
  • 10
  • I will test 2nd one what you place here – yamuna Jan 02 '15 at 10:25
  • 1
    Sure, Let me know if you get stuck somewhere! – gsanskar Jan 02 '15 at 10:25
  • Actually in some mobiles in soft keyboard there is a key button Done after all values entered – yamuna Jan 02 '15 at 10:27
  • Yeah you can detect the key event for done key. Follow the link below : http://stackoverflow.com/questions/5077425/android-detect-done-key-press-for-onscreen-keyboard @yamuna – gsanskar Jan 02 '15 at 10:29
  • I am getting confused my testing mobile had done key so after all values entered i can go with done button so it hides the soft keyboard so i have no problem with this. All mobiles will get done option? – yamuna Jan 02 '15 at 10:29
  • Updated my answer . Yeah all the edittexts will open a soft keyboard with DONE button, until and unless the EditText is single line. @yamuna – gsanskar Jan 02 '15 at 10:33
  • No.. I just want done button after the edit text values entered. I have that doubt only is all mobiles display done key? – yamuna Jan 02 '15 at 10:44
  • Yeah they will! @yamuna – gsanskar Jan 02 '15 at 10:45
  • New Line button instead of done would be shown if your edittext is multiline – gsanskar Jan 02 '15 at 11:08
0

Hiding keyboard is not a big question ,but u need to confirm "when ?" you need to call

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);

for hiding softkeyboard

try to add android:imeOptions="actionNext" in your edittext xml file and

edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                boolean flag= false;
                if (i == EditorInfo.IME_ACTION_NEXT) {
                    flag= true;
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);
                }
                return flag;
            }
        });

this code will hide your soft keyboard on click next in keyboard

Jitty Aandyan
  • 1,994
  • 1
  • 13
  • 12