Jacques René Mesrine
Jacques René Mesrine

Reputation: 47805

What is the native way of implementing Publish Subscribe between Android widgets?

I have a custom EditText and a TextView in an Activity. The custom EditText traps for key presses and calculates the number of character entered and wants to publish the character count to the TextView. Should I use the java.util.Observable/Observer way? Or is there a more native android method to achive this?

Upvotes: 0

Views: 503

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006604

Observable/Observer is probably fine in the abstract.

For EditText/TextView, you could use addTextWatcher() rather than subclassing EditText to support your character count.

And bear in mind that you should really test this stuff with the soft keyboard, as I am under the impression that per-keystroke event behavior changes when users use the soft keyboard instead of the G1's QWERTY keyboard.

Upvotes: 2

Related Questions