question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make @OnTextChanged more useful when using multiple Views

See original GitHub issue

@OnTextChanged can be applied to methods with different signatures that mirror TextWatcher’s before/after/onTextChanged() methods. But none of those possible signatures include the View that was annotated. When specifying multiple Views, it doesn’t seem to be possible to associate that callback to the View whose text changed. For example:

@OnTextChanged({R.id.edittext_foo, R.id.edittext_bar})
protected void handleTextChange(Editable editable) {
    // I have the Editable that changed but which View's Editable is it???
}

For comparison, the signatures accepted for @OnCheckChanged and @OnClick include the View. Are there technical reasons why it would be impractical to include the Editable’s View as a parameter?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:12
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
arunseshagiricommented, Oct 4, 2017

below code can be used to get the current view,

//Inside a activity View view = getCurrentFocus();

with this view object you can get the id view.getId(); and use the same for comparison.

Hope this helped.

1reaction
JakeWhartoncommented, Jul 13, 2016

My biggest objection is that this would require specialization of a mechanism which is currently general. The reason those other listeners allow receiving the view is because their associated callback does as well.

On Tue, Jul 12, 2016 at 6:31 PM Brandon Rich notifications@github.com wrote:

@OnTextChanged can be applied to methods with different signatures that mirror TextWatcher’s before/after/onTextChanged() methods. But none of those possible signatures include the View that was annotated. When specifying multiple Views, it doesn’t seem to be possible to associate that callback to the View whose text changed. For example:

@OnTextChanged({R.id.edittext_foo, R.id.edittext_bar}) protected void handleTextChange(Editable editable) { // I have the Editable that changed but which View’s Editable is it??? }

Not being able to associate the change to the View that changed prevents me from being able to use Butterknife for these listeners. In contrast, the signatures accepted for @OnCheckChanged and @OnClick include the View.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/672, or mute the thread https://github.com/notifications/unsubscribe/AAEEEWjOZUCsHr6dVQnZu3-kyN-Q6w7dks5qVBXKgaJpZM4JK5Op .

Read more comments on GitHub >

github_iconTop Results From Across the Web

onTextChanged Event for many Textboxes c# - Stack Overflow
Yes, you can create a single event - and then subscribe all the text boxes to the same event handler in your class,...
Read more >
TextBox.OnTextChanged(EventArgs) Method (System.Web.UI ...
Creates a multi selection check box group that can be dynamically created by binding the control to a data source. GridView.RowCommand Event (System.Web.UI....
Read more >
How to Handle Multiple Inputs with a Single onChange ...
Besides handling just one input, a single onChange handler can be set up to handle many different inputs in the form.
Read more >
Handle changes to a text field - Flutter documentation
Handle changes to a text field · 1. Supply an onChanged() callback to a TextField or a TextFormField · 2. Use a TextEditingController....
Read more >
Backbone.js
Models and Views. Model-View Separation. The single most important thing that Backbone can help you with is keeping your business logic separate from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found