I have an EditText
in which I'm setting drawables
to the right of the EditText
. I'm switching those drawables
with different scenarios. I have clearText
and refreshIcon
as my drawables. These both are changing correctly but I'm not able to get separate events for both of my drawables
. Here is what I'm doing for clearing text from the EditText
:
String value = "";
final Drawable x = getResources().getDrawable(R.drawable.clear_text);
x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
getUrl.setCompoundDrawables(null, null, value.equals("") ? null : x,
null);
getUrl.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (getUrl.getCompoundDrawables()[2] == null) {
return false;
}
if (event.getAction() != MotionEvent.ACTION_UP) {
return false;
}
if (event.getX() > getUrl.getWidth() - getUrl.getPaddingRight()
- x.getIntrinsicWidth()) {
getUrl.setText("");
getUrl.setCompoundDrawables(null, null, null, null);
}
return false;
}
});
When I click clearText
drawable
it clears the text. It was nice and easy.
Now, I have another drawable
i.e. refreshIcon
, when on EditText
refreshIcon
is showing up it is not getting particular event for refresh purpose.
I have used the same code as of clearText
for refreshIcon
. I'm not able to print the Log
when refreshIcon
is clicked/touched
.
What am I doing worong? Any kind of help will be appreciated.