When we pop up a dialog, assuming this dialog need to input data, and then determine the need to close the input method, the general system of hide, with the show method will always have a variety of problems, the most overbearing solution is to write a timer, timed pop-up or turn off the input method.
ImportJava.util.Timer;ImportJava.util.TimerTask;ImportAndroid.content.Context;ImportAndroid.view.View;ImportAndroid.view.inputmethod.InputMethodManager;ImportAndroid.widget.EditText; Public classInputtools {//Hide Virtual keyboard Public Static voidHidekeyboard (View v) {Inputmethodmanager Imm=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {Imm.hidesoftinputfromwindow (), V.getapplicationwindowtoken (),0 ); } } //Show Virtual keyboard Public Static voidShowkeyboard (View v) {Inputmethodmanager Imm=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service); Imm.showsoftinput (v,inputmethodmanager.show_forced); } //force display or shutdown of the system keyboard Public Static voidKeyBoard (FinalEditText Txtsearchkey,FinalString status) {Timer Timer=NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {Inputmethodmanager m=(Inputmethodmanager) Txtsearchkey.getcontext (). Getsystemservice (Context.input_method_service); if(Status.equals ("open") {m.showsoftinput (txtsearchkey,inputmethodmanager.show_forced); } Else{M.hidesoftinputfromwindow (Txtsearchkey.getwindowtoken (),0); } } }, 300); } //force hidden virtual keyboard via timer Public Static voidTimerhidekeyboard (FinalView v) {Timer Timer=NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {Inputmethodmanager IMM=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {Imm.hidesoftinputfromwindow (V.getapplicationwindowtoken ()),
0 ); } } }, 10); } //does the IME show Public Static BooleanKeyBoard (EditText EditText) {BooleanBOOL =false; Inputmethodmanager IMM=(Inputmethodmanager) Edittext.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {bool=true; } returnbool; }}