我创建了一个这样的方法,它包含更多方法。但是,我不知道我是否需要顶级方法 - appNextCallAd()
。我想澄清一下,点击按钮调用adLoaded()
方法的最佳做法是什么。我应该把它变成一个班吗?如果有,怎么样?如果我必须从多个活动中拨打adLoaded()
,最好的方法是什么?感谢。
public void appNextCallAd() {
// Get callback for ad loaded
interstitial_Ad.setOnAdLoadedCallback(new OnAdLoaded() {
@Override
public void adLoaded() {
interstitial_Ad.showAd();
}
});
// Get callback for ad opened
interstitial_Ad.setOnAdOpenedCallback(new OnAdOpened() {
@Override
public void adOpened() {
}
});
// Get callback for ad clicked
interstitial_Ad.setOnAdClickedCallback(new OnAdClicked() {
@Override
public void adClicked() {
}
});
// Get callback for ad closed
interstitial_Ad.setOnAdClosedCallback(new OnAdClosed() {
@Override
public void onAdClosed() {
}
});
// Get callback for ad error
interstitial_Ad.setOnAdErrorCallback(new OnAdError() {
@Override
public void adError(String error) {
switch (error) {
case AppnextError.NO_ADS:
Log.v("appnext", "no ads");
break;
case AppnextError.CONNECTION_ERROR:
Log.v("appnext", "connection problem");
break;
default:
Log.v("appnext", "other error");
}
}
});
}
这是按钮点击事件;
private OnClickListener cancelBtn = new OnClickListener() {
@Override
public void onClick(View V) {
try {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch (NullPointerException ex) {
Log.e("TEST2", ex.toString());
}
//How to call adLoaded() here?!
}
};
答案 0 :(得分:0)
当你调用方法来设置回调时,只需使用"这个"并实现接口。
您的课程将类似于:
const somethingEpic = action$ =>
action$.ofType(SOMETHING)
.mergeMap(() =>
fromEventSource('http://some-url.com')
.map(message => ({
type: MESSAGE,
payload: message
}))
.catch(e => Observable.of({
type: SOMETHING_ERROR,
payload: e,
error: true
}))
);
然后您就可以从onClick调用 adLoaded 方法了。我建议这样做:
class yourclass implements OnAdLoaded {
public void appNextCallAd() {
// Get callback for ad loaded
interstitial_Ad.setOnAdLoadedCallback(this);
...
}
...
@Override
public void adLoaded() {
... do your stuff...
}