Make the button visible at a given time

Asked

Viewed 422 times

0

Hi, I’m trying to get that button "X" close the ad appear after 15 seconds.

I don’t know the correct function for this but I did it on the basis of appearing interstitial ads from admob.

See my code:

      MobileAds.initialize(getApplicationContext(), getString(R.string.ID_APP_ADMOB));
        final LinearLayout adscontainer = (LinearLayout) findViewById(R.id.adsContainer);
        final AdView mAdView = (AdView) findViewById(R.id.adView);
        final Button closeAd = (Button) findViewById(R.id.closeAd);
        final FrameLayout frameAds = (FrameLayout) findViewById(R.id.frameAds);
        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        ///tempo contado em milisegundos
        TempoCorrido = new CountDownTimer(15000, 50) {
            @Override
            public void onTick(long millisUnitFinished) {
                TempoMilisegundos = millisUnitFinished;
            }

            @Override
            public void onFinish() {
                closeAd.setVisibility(View.VISIBLE); /// Exibi o botão X
            }
        };

XML:

    <Button
    android:id="@+id/closeAd"
    android:background="@android:drawable/ic_menu_close_clear_cancel"
    android:layout_gravity="end"
    android:visibility="invisible"
    android:layout_width="25dp"
    android:layout_height="25dp" />

The problem is that the button is not showing after 15 seconds. How to proceed?

  • I do not understand why they denied my question and left no comment!

  • 1

    Missing call the method start() after the creation of the task Tempocorrido

  • Can you give me an example? I’m beginner and not java manjo yet, I did these things seeing tutorial.

1 answer

0


Call the method start() after the creation of the object and see if it works

            TempoCorridoX = new CountDownTimer(15000, 50) {
            @Override
            public void onTick(long millisUntilFinished) {
            //// nada faz
            }

            @Override
            public void onFinish() {
                closeAd.setVisibility(View.VISIBLE); /// Exibi o botão X de fechar o anúncio
            }
        }.start();
  • I will test and put the result!

  • The button didn’t appear, it continued the same

  • In XML leave the Button as Visible. Called the method start()?

  • Get a way here, give me permission to edit your answer and put how it worked.

  • What you got. You can edit.

  • All right, thank you very much!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.