Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit fe65e67

Browse files
authored
fix(compose): autocomplete hits loading (#42)
1 parent 513895a commit fe65e67

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

showcase-compose/src/main/kotlin/com/algolia/instantsearch/showcase/compose/ui/component/AutoCompleteTextField.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.text.TextWatcher
55
import android.view.View.inflate
66
import android.widget.ArrayAdapter
77
import android.widget.AutoCompleteTextView
8+
import android.widget.ListAdapter
89
import androidx.compose.runtime.Composable
910
import androidx.compose.ui.Modifier
1011
import androidx.compose.ui.viewinterop.AndroidView
@@ -33,15 +34,15 @@ fun AutoCompleteTextField(
3334
},
3435
update = {
3536
val autoComplete = it.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView)
36-
val adapter = autoComplete.asArrayAdapter()
37+
val adapter = autoComplete.adapter.asArrayAdapter()
3738
adapter?.clear()
3839
adapter?.addAll(suggestions)
3940
}
4041
)
4142
}
4243

4344
@Suppress("UNCHECKED_CAST")
44-
private fun AutoCompleteTextView.asArrayAdapter() = this as? ArrayAdapter<String>
45+
private fun ListAdapter.asArrayAdapter() = this as? ArrayAdapter<String>
4546

4647
private fun textWatcherOf(searchBoxState: SearchBoxState) =
4748
object : TextWatcher {

showcase-compose/src/main/res/layout/autocompletetextfield.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
android:id="@+id/autoCompleteTextView"
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
12+
android:imeOptions="actionSearch"
13+
android:inputType="text"
14+
android:hint="@string/search_items"
1215
/>
1316

1417
</com.google.android.material.textfield.TextInputLayout>

0 commit comments

Comments
 (0)