'Android TextInputLayout set different action for endicons in single onendiconclicklistener
There is a textinputlayout in which endicon changes upon text input.
And each end icon have separate onclick listeners.
I need a single end icon click listener and in it, based on end icon id / drawable id, call separate methods.
And I also dont want to set drawable each time the text changes. Please help me. Thanks a lot!
Below are the code:
inputMessageTIET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length() > 0){
inputMessageTIL.setEndIconDrawable(R.drawable.ic_message_send_icon);
inputMessageTIL.setEndIconOnClickListener(v -> {
activityContext.runOnUiThread(() -> Toast.makeText(activityContext, "First End Icon Clicked", Toast.LENGTH_SHORT).show());
}
});
} else {
inputMessageTIL.setEndIconDrawable(R.drawable.ic_mic);
inputMessageTIL.setEndIconOnClickListener(v -> {
activityContext.runOnUiThread(() -> Toast.makeText(activityContext, "Second End Icon Clicked", Toast.LENGTH_SHORT).show());
}
});
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
