title: Android: How to display an AdView in a row after every n-th row in a GridView?
body: <p>I have a GridView with two columns and I want to show a native ad after every n-th row. I have searched a lot on the internet but couldn't find any solution.</p>
  
  <p>I have tried a few libraries/sdks like <a href="https://github.com/clockbyte/admobadapter" rel="nofollow noreferrer">https://github.com/clockbyte/admobadapter</a> but have been unable to solve my problem.</p>
  
  <p>Code Try:</p>
  
  <pre><code>public View getView(final int position, View row, ViewGroup parent) {
          MyHolder holder = null;
          boolean showAd = proVersion == false &amp;&amp; (position % 8 == k);
          if (showAd) {
              AdView adView = adList.get(position);
              if (adView == null) {
                  AdView adViewNew = new AdView((Activity) context, AdSize.BANNER, context.getResources().getString(
                          R.string.adId));
                  adViewNew.loadAd(Utils.getAdRequest("gps", lat, lng, keywords));
                  adList.add(position, adViewNew);
                  return adViewNew;
              } else {
                  return adView;
              }
          } else if (row == null || row instanceof AdView) {
              LayoutInflater inflater = ((SherlockActivity) context).getLayoutInflater();
              row = inflater.inflate(viewResourceId, parent, false);
              holder = new MyHolder();
              holder.textName = (TextView) row.findViewById(R.id.name);
              row.setTag(holder);
          } else {
              holder = (MyHolder) row.getTag();
          }
          holder.textName.setText(items.get(position).getName());
  
          // more code
  
          return row;
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Mkd8f.jpg" rel="nofollow noreferrer">I want to achieve something like this:</a></p>