在Android中设置委托

时间:2015-11-08 17:26:02

标签: java android delegates

我需要完成以下任务:

AdBuddiz.RewardedVideo.setDelegate(delegate);

此SDK的文档说“委托必须实现以下接口”:

interface AdBuddizRewardedVideoDelegate {
  void didComplete();    // user fully watched the video, give the reward here 

  // optional
  void didFetch();       // a video is ready to be displayed
  void didFail(AdBuddizRewardedVideoError error); // SDK was unable to fetch or show a video
  void didNotComplete(); // an error happened during video playback
}

我熟悉iOS中的委托,但是我不熟悉它在Java / Android中是如何工作的。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

我不熟悉您正在使用的类,但看起来您只需要实现此接口。您可以使用匿名类来完成此操作。像

这样的东西
myRewardVideo.setDelegate(new AdBuddizRewardedVideoDelegate() {

    @Override
    public void didComplete() {
        // write what you want to happen here.
    }

    @Override
    public void didFetch() {
        // write what you want to happen here.
    }

    @Override
    public void didFail(AdBuddizRewardedVideoError error) {
        // write what you want to happen here.
    }

    @Override
    public void didNotComplete() {
        // write what you want to happen here.
    }
});

最后3种方法是可选的,所以如果你不希望在这些情况下发生任何事情,你可以摆脱这些方法。