Last active
October 14, 2020 08:00
-
-
Save Tamkien/46e46b66f7b222f82d5b0a9fc4b58526 to your computer and use it in GitHub Desktop.
Kotlin code for creating OnTouchListener on a DrawableEnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
editTextNumber.setOnTouchListener(object : View.OnTouchListener{//editTextNumber is the id of my EditText that contains the drawable | |
@SuppressLint("ClickableViewAccessibility") | |
override fun onTouch(view: View?, event: MotionEvent?): Boolean { | |
if (event?.action == MotionEvent.ACTION_UP){ | |
if (event.rawX >= editTextNumber.right - editTextNumber.compoundDrawables[2].bounds.width()){ //*Why [2]? See below | |
Log.d("DrawableEnd", "Pressed")//Insert your action here | |
return true | |
} | |
} | |
return false | |
} | |
}) | |
/* DRAWABLE_LEFT = 0 | |
DRAWABLE_TOP = 1 | |
DRAWABLE_RIGHT = 2 | |
DRAWABLE_BOTTOM = 3*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment