title: How to add admob ads in fragments in android studio?
body: <p>I would love to add admob ads to fragments in my app. I have already added the ads in the XML files. I am having trouble in the java part, however. Could you please share the java code with rootview? I have checked other articles but I am confused.</p>
  <p>HomeFragment.java</p>
  <pre><code>private AdView mAdView;
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootview = inflater.inflate(R.layout.fragment_home, container, false);
      ButterKnife.bind(this, rootview);
      mFragmentPositionMap = CommonCodeUtils.getInstance().fillNavigationItemsMap(true);
  
      mAdView = findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder().build();
      mAdView.loadAd(adRequest);    
  
      imagesToPdf.setOnClickListener(this);
      qrbarcodeToPdf.setOnClickListener(this);
      textToPdf.setOnClickListener(this);
      viewFiles.setOnClickListener(this);
      viewHistory.setOnClickListener(this);
      splitPdf.setOnClickListener(this);
      mergePdf.setOnClickListener(this);
      compressPdf.setOnClickListener(this);
      removePages.setOnClickListener(this);
      rearrangePages.setOnClickListener(this);
      extractImages.setOnClickListener(this);
      mPdfToImages.setOnClickListener(this);
      addPassword.setOnClickListener(this);
      removePassword.setOnClickListener(this);
      rotatePdf.setOnClickListener(this);
      addWatermark.setOnClickListener(this);
      addImages.setOnClickListener(this);
      removeDuplicatePages.setOnClickListener(this);
      invertPdf.setOnClickListener(this);
      zipToPdf.setOnClickListener(this);
      excelToPdf.setOnClickListener(this);
      extractText.setOnClickListener(this);
      addText.setOnClickListener(this);
  
      mAdapter =  new RecentListAdapter(this);
      recentList.setAdapter(mAdapter);
      return rootview;
      }
  </code></pre>
  <p>Added This To fragment_home.xml</p>
  <pre><code>&lt;com.google.android.gms.ads.AdView
      xmlns:ads=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:id=&quot;@+id/adView&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_centerHorizontal=&quot;true&quot;
      android:layout_alignParentBottom=&quot;true&quot;
      ads:adSize=&quot;BANNER&quot;
      ads:adUnitId=&quot;ca-app-pub-3940256099942544/6300978111&quot;&gt;
  &lt;/com.google.android.gms.ads.AdView&gt;
  </code></pre>
  <p>However, it return an error with the findViewById part. And I would also like to know what should be added to the Manifest file.</p>