From 477e99eec6be43eb116c0430d3779c301f7d2d1f Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 26 Jan 2015 22:42:36 +0100 Subject: [PATCH] AdView now is shown only after the loading is done --- .../java/org/solovyev/android/calculator/AdView.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AdView.java b/android-app/src/main/java/org/solovyev/android/calculator/AdView.java index 1cabb3d3..2feb81c6 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/AdView.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/AdView.java @@ -50,11 +50,10 @@ public class AdView extends FrameLayout { return; } - setVisibility(VISIBLE); - LayoutInflater.from(getContext()).inflate(R.layout.admob, this); admobView = (com.google.android.gms.ads.AdView) findViewById(R.id.admob); - admobView.setVisibility(View.VISIBLE); + if (admobView == null) throw new AssertionError(); + admobView.setAdListener(new AdListener() { @Override public void onAdFailedToLoad(int errorCode) { @@ -63,6 +62,10 @@ public class AdView extends FrameLayout { @Override public void onAdLoaded() { + if (admobView != null) { + admobView.setVisibility(View.VISIBLE); + } + setVisibility(VISIBLE); } });