Created
June 23, 2020 14:51
-
-
Save amirul12/ec9e9c89a3d09390ca24766947e7c6ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomListenerService { | |
public interface MyCustomListener{ | |
public void onSetText(String text); | |
} | |
private List<MyCustomListener> myCustomListeners = new ArrayList<>(); | |
public static volatile CustomListenerService customListenerService; | |
private CustomListenerService(){ | |
if (customListenerService != null){ | |
throw new RuntimeException("use getInstance() to get the sigle instance of this class"); | |
} | |
} | |
public static CustomListenerService getInstance(){ | |
if (customListenerService == null){ | |
synchronized (CustomListenerService.class){ | |
customListenerService = new CustomListenerService(); | |
} | |
} | |
return customListenerService; | |
} | |
public void addCustomListener(MyCustomListener customListener){ | |
this.myCustomListeners.add(customListener); | |
} | |
public void removeCustomListener(MyCustomListener listener){ | |
this.myCustomListeners.remove(listener); | |
} | |
private void updateViewOnCustomEventDone(String text){ | |
for (int i = 0; i < myCustomListeners.size(); i++ ){ | |
this.myCustomListeners.get(i).onSetText(text); | |
} | |
} | |
public void changeValue(String text){ | |
if (text != null){ | |
updateViewOnCustomEventDone(text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment