Is there a way to implement the on click listener on the right drawable of an EditText by using RxBinding?
The only thing I found is:
RxTextView.editorActionEvents(mEditText).subscribeWith(new DisposableObserver<TextViewEditorActionEvent>() {
@Override
public void onNext(TextViewEditorActionEvent textViewEditorActionEvent) {
int actionId = textViewEditorActionEvent.actionId();
if(actionId == MotionEvent.ACTION_UP) {
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
But in this event I can't find the info about the position of the click.
This is the way I did it by using RxJava:
public Observable<Integer> getCompoundDrawableOnClick(EditText editText, int... drawables) {
return Observable.create(e -> {
editText.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
for (int i : drawables) {
if (i == UiUtil.COMPOUND_DRAWABLE.DRAWABLE_RIGHT) {
if (event.getRawX() >= (editText.getRight() - editText.getCompoundDrawables()[i].getBounds().width())) {
e.onNext(i);
return true;
}
}
}
}
// add the other cases here
return false;
});
});
but I feel I'm reinventing the wheel