I am new in Android application development, but I have programming knowledge in iOS. I have started to learn Andriod, yesterday only. I want to hide the keyboard when I click anywhere outside the EditText. But I found a code to hide the keyboard, which is following:
"InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtUserName.getWindowToken(), 0);"
Then I tried as following in my project, but I couldn’t hide the keyboard.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
txtUserName = (EditText)findViewById(R.id.txtUserName);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtUserName.getWindowToken(), 0);
}
My doubt is that do I need to add any touchEvents or keyboardEvents. Please help me.
your question is same as below see it may help you.
http://3.bp.blogspot.com/-aOmfANlocYI/Tm9gJvI7s1I/AAAAAAAAAEA/yBEfcpoGX4U/s1600/3.JPG
make it right if it really helped you.