1

I have been trying a lot to create a invisible button which is show after the Ads is loaded actually.

Before the Ads load, button will never visible.

BUT IF Ads loaded, then Button will be Visible,

How to do it in Android Studio ? Can anyone Explain ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

0

Firstly Add a button in your xml layout and set its VISIBILITY GONE like this :-

           <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Previous Page"
            android:textColor="#000000"
            android:textSize="16dp"
            android:paddingLeft="10dp"
            android:layout_marginTop="10dp"
            android:visibility="gone" />

Find it your java file like this :-

        Button b=(Button)findViewByid(R.id.btn);

And when Ad Loads write this piece of code :-

       b.setVisibility(View.VISIBLE);
Xay
  • 248
  • 3
  • 10
0

Here is solution for your problem. You have to use this method

AdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            // Set Your button visiblity VISIBLE
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            // Set Your button visiblity INVISIBLE
        }
    });

Your AdListener's onReceiveAd() will be called when an ad is available and onFailedToReceiveAd() will be called when an ad isn't available.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sanwal Singh
  • 1,765
  • 3
  • 17
  • 35