Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context
- import android.util.AttributeSet
- import android.view.MotionEvent
- import androidx.appcompat.widget.AppCompatAutoCompleteTextView
- /**
- * Created by Chayan Mistry on 21/04/2023
- * Always Visible AutoComplete Dropdown
- */
- class InstantAutoComplete @JvmOverloads
- /**
- * Constructor
- * @param context Context
- * @param attrs Attribute Set for view
- */
- constructor(context: Context, attrs: AttributeSet? = null) : AppCompatAutoCompleteTextView(context, attrs) {
- /**
- * Get android default attributes
- * https://stackoverflow.com/a/70577844/5280371
- */
- private val sInputType = attrs?.getAttributeIntValue(
- "http://schemas.android.com/apk/res/android",
- "inputType", -1
- ) ?: 0
- init {
- inputType = sInputType
- }
- override fun enoughToFilter(): Boolean {
- return true
- }
- override fun onTouchEvent(event: MotionEvent): Boolean {
- if (event.action == MotionEvent.ACTION_DOWN) {
- performClick()
- }
- return super.onTouchEvent(event)
- }
- override fun performClick(): Boolean {
- if (!isPopupShowing) {
- performFiltering(null, 0)
- showDropDown()
- }
- return super.performClick()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement