Does anyone know if there is anything in Java similar to NotifyPropertyChanged in C#? I have been searching around, and there is no proper answer.
Here is the senerio:
In fact,I am working on an android application. The applications will read data from the remote bluetooth device via the bluetooth socket. Once the data is received from the socket, the data will be decoded from the decoder(it is a class) and update the value to the UI. However, I have a decoder class to decode the data from the bluetooth device and a activity which manage to display the value to UI. I need to pass the decoded value from the decoder to the UI. I would think I need a notifypropertychanged event, so that when there is some updated value from the decode, it will inform the ACTIVITY class to update the UI.
Pure Java (not Android specific) does have an interface typically used for beans to handle property change events that you can use. The classes involved are:
PropertyChangeSupportis the class you would extend in order to fire change notifications inside of your setter methods.PropertyChangeListenerinstances register and listen for change events.PropertyChangeEventobjects encapsulate the data passed with the change.Here’s an article from the Oracle docs describing the interface in more detail.