"android listview search filter custom adapter kotlin" Code Answer's
You're definitely familiar with the best coding language Kotlin that developers use to develop their projects and they get all their queries like "android listview search filter custom adapter kotlin" answered properly. Developers are finding an appropriate answer about android listview search filter custom adapter kotlin related to the Kotlin coding language. By visiting this online portal developers get answers concerning Kotlin codes question like android listview search filter custom adapter kotlin. Enter your desired code related query in the search bar and get every piece of information about Kotlin code related question on android listview search filter custom adapter kotlin.
android listview search filter custom adapter kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val poisArray = listOf(
// See previous sections
)
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)
}
}
Source: spapas.github.io
android listview search filter custom adapter kotlin
override fun getFilter(): Filter {
return object : Filter() {
override fun publishResults(charSequence: CharSequence?, filterResults: Filter.FilterResults) {
mPois = filterResults.values as List<PoiDao>
notifyDataSetChanged()
}
override fun performFiltering(charSequence: CharSequence?): Filter.FilterResults {
val queryString = charSequence?.toString()?.toLowerCase()
val filterResults = Filter.FilterResults()
filterResults.values = if (queryString==null || queryString.isEmpty())
allPois
else
allPois.filter {
it.name.toLowerCase().contains(queryString) ||
it.city.toLowerCase().contains(queryString) ||
it.category_name.toLowerCase().contains(queryString)
}
return filterResults
}
}
}
Source: spapas.github.io
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 {
// Or just return p0
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 {
// See next section
}
}
Source: spapas.github.io
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")
)
Source: spapas.github.io
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>
Source: spapas.github.io
All those coders who are working on the Kotlin based application and are stuck on android listview search filter custom adapter kotlin can get a collection of related answers to their query. Programmers need to enter their query on android listview search filter custom adapter kotlin related to Kotlin code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about android listview search filter custom adapter kotlin for the programmers working on Kotlin code while coding their module. Coders are also allowed to rectify already present answers of android listview search filter custom adapter kotlin while working on the Kotlin language code. Developers can add up suggestions if they deem fit any other answer relating to "android listview search filter custom adapter kotlin". Visit this developer's friendly online web community, CodeProZone, and get your queries like android listview search filter custom adapter kotlin resolved professionally and stay updated to the latest Kotlin updates.