I am looking for an example of an interface with a listener, so any class implementing the interface also needs to have the listener. For the interface below I wanted to have a listener to callback when the ImageView is loaded. One class will use a bitmap, the other will use a uri. In either case
My interface
public interface ITokenMessageService {
public void sendAcknowledgement();
public void sendReceived();
public void sendFinished();
public void displayToken(ImageView imageView, [here is where I want the callback]);
}
This may seem rather simple but the queries for interface returned a lot of UX responses and because you implement an interface for a listener, there were a lot of responses for that as well, so I was having trouble finding an example.
public interface ITokenMessageService {
public void sendAcknowledgement();
public void sendReceived();
public void sendFinished();
public void displayToken(ImageView imageView, YourCallback callback );
//You could have a get function in your interface
//thus anything implementing it, needs to have a function that returns
//the callback, ie it has it.
public YourCallback getYourCallback();
}
In reality this doesn't make much sense though, as why would you need to guarantee the implementer also has the callback through an Interface
? If its using the displayToken
function it HAS to have it or have access to it anyways, its a moot point.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.