Dear all,
I wish to seek advice as to why adverts are not appearing on the Nexus 5 emulator that comes with Android Studio. I have added the following code to one of my fragments: This is the first time that I have made use of adverts in my app.
The Fragment is called "Selected Species"
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.selectedspecies, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
layoutManager = new LinearLayoutManager(this.getContext());
recyclerView.setLayoutManager(layoutManager);
MobileAds.initialize(this.getContext(),"ca-app-pub-4826760022871008~7701513470");
mAdView1 = (AdView) view.findViewById(R.id.adView1);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView1.loadAd(adRequest);
mAdView2 = (AdView) view.findViewById(R.id.adView2);
AdRequest adRequest2 = new AdRequest.Builder().build();
mAdView2.loadAd(adRequest2);
if (savedInstanceState != null) {
ArrayChar = savedInstanceState.getStringArray("ArrayChar");
}
The selectedspecies XML layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ebookfrenzy.GramineaeIdentification.SelectedSpecies">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4826760022871008/4709885603">
</com.google.android.gms.ads.AdView>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarSize="20dp"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideInset"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView2"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4826760022871008/4709885603">
</com.google.android.gms.ads.AdView>
</android.support.design.widget.CoordinatorLayout>
The build.gradle file is as follows:
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:11.6.2'
testCompile 'junit:junit:4.12'
Many thanks,
Alasdair Grant