সাত বছর পরে, ছেলেরা, সমস্যাটি একই থাকে। এখানে একটি ফাংশন সহ এমন একটি শ্রেণি রয়েছে যা কোনও বেকায়দায় নিজেকে দেখানোর জন্য মূ .় পপ-আপকে বাধ্য করে। আপনাকে যা করতে হবে তা হ'ল আপনার অটো কমপ্লিট টেক্সটভিউতে একটি অ্যাডাপ্টার সেট করা, এতে কিছু ডেটা যুক্ত করা এবং showDropdownNow()
যে কোনও সময় ফাংশন কল করা ।
@ ডেভিড ভভ্রা এর ক্রেডিট। এটি তার কোডের উপর ভিত্তি করে।
import android.content.Context
import android.util.AttributeSet
import android.widget.AutoCompleteTextView
class InstantAutoCompleteTextView : AutoCompleteTextView {
constructor(context: Context) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
override fun enoughToFilter(): Boolean {
return true
}
fun showDropdownNow() {
if (adapter != null) {
// Remember a current text
val savedText = text
// Set empty text and perform filtering. As the result we restore all items inside of
// a filter's internal item collection.
setText(null, true)
// Set back the saved text and DO NOT perform filtering. As the result of these steps
// we have a text shown in UI, and what is more important we have items not filtered
setText(savedText, false)
// Move cursor to the end of a text
setSelection(text.length)
// Now we can show a dropdown with full list of options not filtered by displayed text
performFiltering(null, 0)
}
}
}