Admob banners without XML

Hello everybody,

I want to use admob banners, but on my main activity I don’t have an XML file (everything is done in view java file). Any suggestions how can I do it?
I tried some time ago, but it was at the top of the activity, I want it to be at the end.

Now I am using leadbolt, where no XML is needed, but I would like to change, because everyday I see many clicks, but no revenue. (for ex. today from this app I have 15 clicks and 0 revenue)

Where the ad will show in the activity is dependent on how you add it to the layout. Is your main layout created with xml or in code?

the activity where I want to show the banner is created in code.

Ok, then the way you would position the banner would be based on how you add it to the layout. But I’m no layout expert, but that’s where I’d start with.

i think you still can do it with no XML

-Download the SDK
-Incorporating the SDK

  • on your onCreate::MainActivity

// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);//replace MY_AD_UNIT_ID with your ad unit ID

// Add the adView to it
layout.addView(adView); //replace layout with your own defined view

// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());

  • on your onDestroy::MainActivity
    public void onDestroy() {
    if (adView != null) {


for the position i am not sure but try to get the index by using myView.getChildCount() and use it with
addView (View child, int index)

This is how you integrate Admob in Libgdx. I think it provides every information you need to create an AdView and add it to your Layout without XML.

I read the article, seems like it will do my job. I will try it as soon as possible. Thank you!