简体   繁体   中英

Admob ad not showing on adview

I am trying to put an adview to my app. I have put an adview on xml and is as follows


<?xml version="1.0" encoding="utf-8"?>       
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"      
android:id="@+id/RelativeLayout1"   
android:layout_width="match_parent"   
android:layout_height="match_parent"   
android:orientation="vertical"
android:padding="10dp" >          

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <!-- Name Label -->

    <TextView
        android:id="@+id/name_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dip"
        android:paddingTop="10dip"
        android:textSize="15sp"
        android:textStyle="bold" />    
</ScrollView>

 <com.google.android.gms.ads.AdView
     android:id="@+id/adView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/ScrollView1"
     ads:adSize="BANNER"
     ads:adUnitId="ca-app-pub-6045707126584551/3116181621"
     android:layout_alignParentBottom="true" >
 </com.google.android.gms.ads.AdView>

</RelativeLayout>

and here is the code that i implemented in order to initialize adview in java. This code is supposed to load the ads.


 public class SingleContactActivity extends Activity {

// JSON node keys
static final String ID = "id";
static final String POS = "position";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_contact);

    // getting intent data
    Intent in = getIntent();

    // Get JSON values from previous intent
    String name = in.getStringExtra(ID);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);

    lblName.setText(name);
     // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("479004f857d93000").build();

    adView.loadAd(adRequest); 
}
}

The ad is not loading on the device when i try it. Any hint or help would be much appriciated. Thank you.

Oh i found the solutions. It was my first time using adview so got a little confusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM