Question

I need to implement AdMob's AdView in the bottom of the Activity with the ListView. I added AbView to my layout sucessfully. My layout file looks like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/archiveLayout"
 android:background="#FFFFFF"
 >
 <ListView  
     android:id="@android:id/list"
     android:layout_alignParentTop="true"
     android:layout_width="fill_parent" 
     android:layout_above="@+id/adView"
     android:background="#000000"
     android:layout_height="wrap_content" 
     />
 <TextView android:id="@android:id/empty"
     android:gravity="center|center"
     android:textColor="#FFFFFF"
     android:textSize="20sp"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:text="You havn't received any quote yet!"
     />
  <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="320dip"
        android:layout_height="50dip"
        ads:adUnitId="ID"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"
        android:layout_alignParentBottom="true"/> 

and that is how I add it in my activity's onCreate:

 @Override
public void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.archive_list);
    setListAdapter(new QuoteAdapter(this, 
            android.R.layout.simple_list_item_1, reverse(getContentDatabase(this))));
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.setEnabled(true);
    adView = new AdView(this, AdSize.BANNER, "ID");
    AdRequest re = new AdRequest();
    re.addTestDevice(AdRequest.TEST_EMULATOR);
    re.addTestDevice("E83D20734F72FB3108F104ABC0FFC738"); 
    adView.loadAd(re);

}

it is shows properly with defined width and height in the bottom of the screen. But there's no content in it. Just the black empty screen. Tell me please what I can do with it.

Was it helpful?

Solution 2

The problem was that I didn't receive ads:adUnitId. When I did it with the admob site everything works properly.

OTHER TIPS

I found it much easier to just add it solely in the xml file. It looks like you've blended the two ways together. You've got ads:loadOnCreate enabled, and you're also making a new one programmatically. Try doing it just the XML way, it loads up when the page is brought up, and I've had 100% fill rate using the xml only method. No need to complicate things if you're just trying to display it when the xml adview shows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top