Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android on change class event

//It's not possible directly. However, you can make your field private, add getters and setters, and create a method of adding listeners (this is called the Observer pattern):

interface ConnectionBooleanChangedListener {
    public void OnMyBooleanChanged();
}

public class Connect { 
     private static boolean myBoolean;
     private static List<ConnectionBooleanChangedListener> listeners = new ArrayList<ConnectionBooleanChangedListener>();

     public static boolean getMyBoolean() { return myBoolean; }

     public static void setMyBoolean(boolean value) {
         myBoolean = value;

         for (ConnectionBooleanChangedListener l : listeners) {
             l.OnMyBooleanChanged();
         }
     }

     public static void addMyBooleanListener(ConnectionBooleanChangedListener l) {
         listeners.add(l);
     }
}

//Then, wherever you want to listen to changes of the boolean, you can register a listener:

Connect.addMyBooleanListener(new ConnectionBooleanChangedListener() {
    @Override
    public void OnMyBooleanChanged() {
        // do something
    }
});

//Adding a method to remove listeners is left as an exercise. Obviously, for this to work, you need to make sure that myBoolean is only changed via setMyBoolean, even inside of Connect.
Comment

PREVIOUS NEXT
Code Example
Java :: android capture view and animation 
Java :: para que sirve getcontentpane en java 
Java :: get whatsapp group id flutter 
Java :: java to run colored lines 
Java :: has 8 digit in number 
Java :: A method that returns a stream of JUnit Arguments 
Java :: difference between string vs stringbuffer 
Java :: remove first character from string java 
Java :: sha 1 key throguh java is not working 
Java :: getdatetimeinstance android 
Java :: How to convert Javascript return value to String in Android 
Java :: how to iterate list in java selenium 
Java :: create a class 
Java :: licenceurl 
Java :: Arraylist imp for recursion 
Java :: get time zone from co-ordinates java 
Java :: call c function from java 
Java :: java coding standards for constants 
Java :: foreign keys in json 
Java :: javalin pom 
Java :: x/=y is the same as x=x/y 
Java :: last element array java 
Java :: make handler running continuously 
Java :: android gradle plugin requires java 11 problem 
Java :: java instanciar objeto File 
Java :: demo application using stomp js and node js 
Java :: List of tuple to map + jpa 
Java :: set class return type by jenric in java 
Java :: spigot wolf death message 
Java :: android studio doesnt work when in full screen mac os 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =