0

From a Fragment, I am using a SearchView inside an AlertDialog and I would like the keyboard's 'Done' button to dismiss the keyboard. For some reason it is not working.

Here is my AlertDialog"

val mBuilder =
        AlertDialog.Builder(context!!, Theme_DeviceDefault_Light_NoActionBar_Fullscreen)
val mView = View.inflate(activity!!, R.layout.list_search, null)
mBuilder.setView(mView)
val dialog = mBuilder.create()
val searchView = view.findViewById<SearchView>(R.id.search_view)
dialog.show()

searchView.setImeOptions(EditorInfo.IME_ACTION_DONE)

searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
    override fun onQueryTextChange(newText: String): Boolean {
        adapterWithSearch.filter(newText)
        return true
    }

    override fun onQueryTextSubmit(query: String): Boolean {
        adapterWithSearch.filter(query)
        return true
    }
})

And here is my SearchView:

<SearchView
    android:id="@+id/searchView"
    style="@style/AppTheme.Searches"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:actionViewClass="android.support.v7.widget.SearchView"
    android:iconifiedByDefault="false"
    android:imeOptions="actionDone"
    android:inputType="text"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:clickable="true" />

I would like the keyboard to be dismissed, not the AlertDialog. Anyone has an idea of why the keyboard isn't being dismissed?

PhilBlais
  • 1,076
  • 4
  • 13
  • 36
  • You want to dismiss the keyboard or the dialog? – Sergio Feb 19 '20 at 20:22
  • you want that if you press done the keyboard swipe down become invisible? – trocchietto Feb 19 '20 at 20:22
  • I want the keyboard to be dismissed, not the AlertDialog – PhilBlais Feb 19 '20 at 20:24
  • I edited, Is the searchView a `SearchView` object? in the case you have a generic view, or I gave a link to another post where `SearchView` is a proper` SearchView ` component – trocchietto Feb 19 '20 at 20:31
  • You'd add a call to hide the keyboard in the onQueryTextSubmit function. Your current code isn't doing that. If you search for "close keyboard android" you'll find dozen of old questions – Gabe Sechan Feb 22 '20 at 07:00

1 Answers1

0

Probably I am not seeing correctly what you are trying to do but I can not see where are you trying to dismiss the keyboard. For this action you have two alternatives:

Try to see this and hope it is helpful

Close/hide the Android Soft Keyboard with Kotlin

You have here different ways to dismiss a keyboard. I don't see more complexity in this question.

Also I found this --> How to dismiss keyboard in Android SearchView?

Sergio
  • 725
  • 1
  • 7
  • 20