i have one static method in kotlin to hide soft keyboard, it works in java if i pass EditText, TextView as second parameter of method.
But in kotlin it gives error,
Error:(56, 71) Type mismatch: inferred type is EditText? but View was expected
i tried to change View to EditText in function, but it doesn't work for TextView
Also tried to change View to Any, but applicationWindowToken gives error.
This is common function in app.
companion object {
fun hideSoftKeyboard(activity: Activity, view: View) {
val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.applicationWindowToken, 0)
}
}
hideSoftKeyboardis not aView, as you defined in the method signature, but a nullableEditText. In addition to @kurt's answer, you can perform a null-check before calling the method - user2340612