INSERT GRAPHIC HERE (include hyperlink in image)
Subtitle or Short Description Goes Here
| /* | |
| * Copyright 2019 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
| package de.vkay.customviews.widget; | |
| import android.animation.ObjectAnimator; | |
| import android.content.Context; | |
| import android.graphics.Canvas; | |
| import android.graphics.Color; | |
| import android.graphics.LinearGradient; | |
| import android.graphics.Matrix; | |
| import android.graphics.Paint; | |
| import android.graphics.PorterDuff; |
| When a user interacts with a UI element the various listeners are called in a top down order. (For example: OnTouch -> OnFocusChange -> OnClick.) If a listener has been defined (with setOn...Listener) and it consumes this event: the lower priority listeners will not be called. By its nature the first time you touch an EditText it receives focus with OnFocusChangeListener so that the user can type. The action is consumed here therefor OnClick is not called. Each successive touch doesn't change the focus so the event trickles down to the OnClickListener. | |
| Basically, you have three choices: | |
| Set the focusable attribute to false in your XML: | |
| android:focusable="false" | |
| Now the OnClickListener will fire every time it is clicked. But this makes the EditText useless since the user can no longer enter any text... | |
| Implement an OnFocusChangeListener along with the OnClickListener: |