Skip to content

SearchMode.OnSubmit not working with EditText #407

Open
@Zineddine231

Description

@Zineddine231

Describe the bug 🐛
i'm using algolia search and instant search library in my project, The problem is that when i set the searchMode to AsYouType the search works perfectly fine and i get the expected results, but when i change it to onSubmit the search will not initiate.

To Reproduce 🔍
first i thought that the problem was in the search view from the material components, and since algolia doesn't support it i've changed it to a basic EditText. But even with edit text and it is the same problem.
my plan is to find out how to make it work with the editText and after that use searchView.editText, because the SearchView has a child EditText.

Here's how i declare the edit text in my layout XML file:
`
<EditText

    android:id="@+id/search"

    android:layout_width="match_parent"

    android:layout_height="@dimen/_42sdp"

    android:hint="edittext hint"

    android:imeOptions="actionSearch"

    android:maxLines="1"

    android:singleLine="true" />`

and this is the backend side:

`
private lateinit var connection: ConnectionHandler
private lateinit var recyclerView: RecyclerView
private lateinit var editText: EditText
private lateinit var searchBoxView: SearchBoxViewEditText

// Initialize the HitsSearcher
private val searcher = HitsSearcher(
    applicationID = ApplicationID("############"),
    apiKey = APIKey("######################"),
    indexName = IndexName("###"),
)
private var adapterKt = AdapterKt()

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    val view = inflater.inflate(R.layout.fragment_search_kt, container, false)

    editText = view.findViewById(R.id.search)
    searchBoxView = SearchBoxViewEditText(editText)

    recyclerView = view.findViewById(R.id.recyclerView)
    val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
    layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
    recyclerView.layoutManager = layoutManager
    recyclerView.adapter = adapterKt

    val searchBox = SearchBoxConnector(searcher, searchMode = SearchMode.OnSubmit)
    connection = ConnectionHandler(searchBox)
    connection += searchBox.connectView(searchBoxView)


    connection += searcher.connectHitsView(adapterKt) { response ->
        val hits = response.hits.deserialize(PostModelKt.serializer())
        adapterKt.setHits(hits) as List<PostModelKt>
    }

    searcher.searchAsync()

    return view
}`

PS: When using the searchView from ViewAppCompat the search works perfectly fine with onSubmit search mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions