MaterialSearchBar icon indicating copy to clipboard operation
MaterialSearchBar copied to clipboard

Setting CustomSuggestionAdapter

Open hawajka76 opened this issue 3 years ago • 1 comments

Hello, I am trying to define a customsuggestionadapter using the method MaterialSearchBar.setCustomSuggestionAdapter searchBar.setCustomSuggestionAdapter(suggestionsAdapter)

I am trying to implement my own callbacklisteners for the custom suggestion adapter which implements com.mancj.materialsearchbar.adapter.SuggestionsAdapter

suggestionsAdapter = DefaultSuggestionsAdapter(LayoutInflater.from(context)) .setListener(object: SuggestionsAdapter.OnItemViewClickListener{ override fun OnItemClickListener(position: Int, v: View?) { TODO("Not yet implemented") } override fun OnItemDeleteListener(position: Int, v: View?) { TODO("Not yet implemented") } })

When I do this however I get an error saying Type mismatch: inferred type is Unit but SuggestionsAdapter<*, *>? was expected

I'm somewhat new to Android programming, so I suspect I'm missing something simple. What could be a good way to fix this?

hawajka76 avatar Jun 21 '21 23:06 hawajka76

I managed to get it working using the following code. Still not quite sure why, if anyone could explain that would be very helpful.

suggestionsAdapter = DefaultSuggestionsAdapter(LayoutInflater.from(context)) if (suggestionsAdapter is DefaultSuggestionsAdapter) (suggestionsAdapter as DefaultSuggestionsAdapter).setListener(object : SuggestionsAdapter.OnItemViewClickListener{})

hawajka76 avatar Jun 22 '21 00:06 hawajka76