1
Someone would have how to show me an Observer structure within android?
I was trying to build one like the java, but I was unsuccessful.
My test was done as follows:
- I created a
class Banco
and aclass ClienteObservable
; - At the bank I have the methods of notification, and
adicionarObserver
(that I pass the ball toclienteObservable
); - In the
class ClienteObservable
I have the methodupdate
, who will carry out an action upon being notified.
This is the logic I have about Project Observer Standard, but I don’t know how to structure it in android, someone could develop something very basic to show me?
It follows below the Code:
Na Class Banco
In Class clienteObservable
Could you post the code you implemented in java? Taking advantage you can leave the classes with the default Java with the first letter uppercase.
– Leonardo Otto
I added the image, and saw that the method notify this without any action with the observer, I figured it might be another strength to use the Observer
– user3456780
What error is having on android?
– Leonardo Otto
No error, just not executed anything, I put for every time the observer receives a notification, it displays a Toast, and it does not run, like and I flirted, my method notify Observeer is not running anything(I think), I will test when I get from the service.
– user3456780
You need to explicitly call notifyObservers every time you change your object. the same way I put in my class in the answer below.
– Leonardo Otto