0

I am in the process of implementing a new layout. This layout will also have an input box, and I want that as soon as the length of the text (whatever is input by the user) reaches a certain length K, a function myFunc in another class ( which already exists seperately) is triggered.

So, this would be something like:

TextView myView = (TextView) findViewById (R.id.myInputBox); 

And I want that whenever the length of the input by user in myView reaches length K , a function myFunc gets triggered.

I just wanted to ask, what would be the best way to do this? I have been going through a number of approaches:

  1. Callback
  2. Listener
  3. Broadcast

I am leaning towards #1 since #3 is expensive as an operation (since this layout will be accessed by users frequently). I am very new here, so I have been learning about callbacks in Android, and I am aware that I will need to define an event and then also define an interface with corresponding method. Can anyone help me where this definiton of event go, and where exactly will I define the callback method?

Thanks!

Edit: I have been advised that my question is similar to How to make KeyDown and KeyUp on android device? but I just feel the OP in the other question wanted to capture each keystroke that user is pressing. In my case, I am just looking forward to capturing the length of the input what the user has entered.

John Doe
  • 185
  • 1
  • 13

0 Answers0