I made a image thread class that runs the update method in the instance that is loading the image:
public class ImageThread implements Runnable {
private Bitmap image;
private String url;
private CustomEventField c;
public ImageThread(String url, CustomEventField c){
this.url = url;
this.c = c;
}
public void notifyUs(){
this.c.update(image);
}
public void run() {
Bitmap img = downloadImage.connectServerForImage(this.url); //data processing
image = img;
notifyUs();
}
}
I send the context in the constructor, however I can only use it for CustomEventField. What if I wanted to use this image class for other classes? I could just make another copy of this class, but I want to keep things organized.
Define a separate interface type that all of your classes can then implement as needed, eg:
ImageThreadCallback.java:
ImageThread.java:
CustomEventField.java:
CustomEntryField.java: