filterresults android add hidden values code example
Example 1: android listview search filter custom adapter kotlin
inner class PoiAdapter(context: Context, @LayoutRes private val layoutResource: Int, private val allPois: List<PoiDao>):
ArrayAdapter<PoiDao>(context, layoutResource, allPois),
Filterable {
private var mPois: List<PoiDao> = allPois
override fun getCount(): Int {
return mPois.size
}
override fun getItem(p0: Int): PoiDao? {
return mPois.get(p0)
}
override fun getItemId(p0: Int): Long {
return mPois.get(p0).id.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view: TextView = convertView as TextView? ?: LayoutInflater.from(context).inflate(layoutResource, parent, false) as TextView
view.text = "${mPois[position].name} ${mPois[position].city} (${mPois[position].category_name})"
return view
}
override fun getFilter(): Filter {
}
}
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>
Example 3: android listview search filter custom adapter kotlin
val poisArray = listOf(
PoiDao(1, "Taco Bell", "Athens", "Restaurant"),
PoiDao(2, "McDonalds", "Athens","Restaurant"),
PoiDao(3, "KFC", "Piraeus", "Restaurant"),
PoiDao(4, "Shell", "Lamia","Gas Station"),
PoiDao(5, "BP", "Thessaloniki", "Gas Station")
)