I have a edittext and a spinner. When I touch on the edittext the keyboard appears, after completed the text editing I touch on the dropdown arrow of the spinner but the keyboard doesn't disappears automatically. Please give me some solution. I tried this code
InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(SetUpProfileActivity.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mDateOfBirth.getWindowToken(), 0);
This is the xml
<LinearLayout
android:id="@+id/outerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<TextView
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/profile_name"
android:textColor="#ffffff" />
<EditText
android:id="@+id/profile_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/txtbox"
android:singleLine="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/dateofbirth"
android:textColor="#ffffff" />
<Spinner
android:id="@+id/dob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/dropdown" />
Tap the back button on your Android. It's the left-pointing arrow button at the bottom of the screen, either at the bottom-left or bottom-right corner. The keyboard is now hidden. The back button may be a physical button or on the touch screen.
To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);
You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.
Try this code, I hope it will work for you.
mSpinner.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
return false;
}
}) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With