filter a list in android code example
Example 1: android listview search filter custom adapter kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val poisArray = listOf(
)
val adapter = PoiAdapter(this, android.R.layout.simple_list_item_1, poisArray)
autoCompleteTextView.setAdapter(adapter)
autoCompleteTextView.threshold = 3
autoCompleteTextView.setOnItemClickListener() { parent, _, position, id ->
val selectedPoi = parent.adapter.getItem(position) as PoiDao?
autoCompleteTextView.setText(selectedPoi?.name)
}
}
Example 2: android listview search filter custom adapter kotlin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="32sp"
android:textAlignment="center"/>
<AutoCompleteTextView
android:layout_marginTop="32dip"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView"/>
</LinearLayout>