Reputation: 41
I learnt to integrate Admob banner ads, In main activity i wrote this code:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
And i also wanted the ads in another activity, So i copy pasted it. But i get a error as:
error: cannot find symbol AdView mAdView = (AdView) findViewById();
Cannot resolve method
symbol: method findViewById()
Error-Image I copy pasted this code in many other class files but it shows the same error.And it only works in MainActivity.java
i want to add ads under the textView.picture
Upvotes: 0
Views: 1067
Reputation: 1
//Just copy and paste the additional 3 lines code into your file.
implementation 'com.google.android.gms:play-services-ads:17.2.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
Upvotes: 0
Reputation: 13669
add this in your CustomPagerAdapter
@Override
public Object instantiateItem(ViewGroup collection, final int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View layout = inflater.inflate(R.layout.chat_layout, collection, false);
RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
AdView mAdView = (AdView) layout.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
Upvotes: 1
Reputation: 13669
Add Adview to your activity_layout.xml
Add this Code in your Activity onCreate
method.
Upvotes: 1