Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove view keypad [duplicate]

Possible Duplicate:
Close/hide the Android Soft Keyboard

I'm a beginner, and have written a simple program to find the roots of a quadratic equation. Entering values in the EditText fields works well, because the virtual keypad pops up so that you can enter your numbers. However, the keypad covers the TextView where your results appear. If the user knows it, they can press the "back" key, and the keypad is removed, revealing the results field. But I want the keypad to disappear when the user touches the "execute" button in the app without pressing the "back" key.

I have been researching this, and some suggested using finish(); But this doesn't only remove the keypad, it also exits the whole program.

So what's the easiest way to only remove the keypad, leaving the underlying TextView displayed? I want to include this in the onClick view that executes the math.

Any suggestions are appreciated.

like image 494
David Brown Avatar asked Dec 27 '12 20:12

David Brown


1 Answers

Just add this code in the onClick method:

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(yourSubmiBtn.getWindowToken(), 0);
like image 95
gezdy Avatar answered Nov 07 '22 08:11

gezdy