0

In my app i am having a recyclerview adapter so i want to show banner ads in between the items, i applied the following code in my adapter class, but its showing an error

Failed to load ad, error code 1

i checked that the appid is correct

public RecyclerViewAdapterMore.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerViewAdapterMore.ViewHolder viewHolder;

        if (viewType == AD_TYPE) {
            AdView adView = new AdView(context);
            adView.setAdSize(AdSize.BANNER);
            adView.setAdUnitId(context.getString(R.string.app_id));

            float density = context.getResources().getDisplayMetrics().density;
            int height = Math.round(AdSize.BANNER.getHeight() * density);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, height);
            adView.setLayoutParams(params);

            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);

            viewHolder = new RecyclerViewAdapterMore.ViewHolder(adView);
        }
        else {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
            viewHolder = new RecyclerViewAdapterMore.ViewHolder(view);
        }

        return viewHolder;
    }
James Z
  • 12,209
  • 10
  • 24
  • 44
Rana Pratap
  • 55
  • 1
  • 9
  • Please refer [this link (It might help)](https://stackoverflow.com/questions/33384445/getting-an-ad-response-errorcode-1/33385216?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Vir Rajpurohit Apr 02 '18 at 05:38
  • Did you just created ad unit ? – Lucifer Apr 02 '18 at 05:42
  • @Lucifer Ya created ad unit, and its working too. – Rana Pratap Apr 02 '18 at 05:46
  • good, is your Test Unit ID working ok ? – Lucifer Apr 02 '18 at 05:48
  • @VirRajpurohit thnx bor, it helped, in place of adunitid i was placing the appid, now changed, but now getting another problem, its showing this message "Not enough space to show ad. Needs 320x49 dp, but only has 116x17 dp", so ads not serving, any idea to resolve this – Rana Pratap Apr 02 '18 at 06:01
  • @RanaPratap It is related to your XML as it is not getting enough room to display the add. Please share your XML code. – Vir Rajpurohit Apr 02 '18 at 06:04
  • @VirRajpurohit i am displaying the ad directly using programming code only not in xml page, the xml page is having a recyclerview and a card view only – Rana Pratap Apr 02 '18 at 06:07
  • The card views are in square grids, so i wanted to put banner ads after 6 cards i.e., after 2 rows each, each row is having 3 cards so after every 6 cards i wanted to display banner ads – Rana Pratap Apr 02 '18 at 06:09
  • @RanaPratap Please refer [this](https://stackoverflow.com/questions/37862315/admob-error-not-enough-space-to-show-ad-needs-320x50-dp-but-only-has-309x0-dp?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Vir Rajpurohit Apr 02 '18 at 06:13

0 Answers0