How can I hide the soft keyboard input while I am using a ScrollView in my LinearLayout?
I have tried to implement the following in my activity class, though none of these solutions produce the intended result:
(1)
@Override
public boolean onTouchEvent(MotionEvent event)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
return true;
}
(2)
@Override
public boolean onTouchEvent(MotionEvent event)
{
ScrollView myScrollView = (ScrollView) findViewById(R.id.scrollview); //of course scrollview was id in layout then
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
return true;
}
(3)
The same as #2, but with LinearLayout instead of ScrollView.
None of these three solutions has worked for me.
One thing I've noticed is that when I remove the ScrollView from the layout.xml file, everything works as intended.
@Override public boolean onTouchEvent(MotionEvent event) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); return true; }function in my previous activities and everything works fine. In my opinione there is some problem with ScrollView component (but I dont know exactly what) beacause as I have said when I put in comment ScrollView component in layout xml file (res/layout-port) everything was ok.