Integrate advertising in a "Recyclerview"

How can I integrate advertising in a "Recyclerview"? I would like to have an AdMob for all two items.Additionally, I would like to delete 4 strings from the pubdate.

This is my actually Code:

private void ProcessXml(Document data) {
        if (data != null) {
            feedItems = new ArrayList<>();
            Element root = data.getDocumentElement();
            Node channel = root.getChildNodes().item(1);
            NodeList items = channel.getChildNodes();
            for (int i = 0; i < items.getLength(); i++) {
                Node cureentchild = items.item(i);
                if (cureentchild.getNodeName().equalsIgnoreCase("item")) {
                    FeedItem item = new FeedItem();
                    NodeList itemchilds = cureentchild.getChildNodes();
                    for (int j = 0; j < itemchilds.getLength(); j++) {
                        Node cureent = itemchilds.item(j);
                        if (cureent.getNodeName().equalsIgnoreCase("title")) {
                        } else if (cureent.getNodeName().equalsIgnoreCase("description")) {
                        } else if (cureent.getNodeName().equalsIgnoreCase("pubDate")) {
                        } else if (cureent.getNodeName().equalsIgnoreCase("link")) {
                        } else if (cureent.getNodeName().equalsIgnoreCase("media:thumbnail")) {
                            //this will return us thumbnail url
                            String url = cureent.getAttributes().item(0).getTextContent();


1 answer

  • answered 2018-01-14 15:55 Alexander Hoffmann

    A RecylcerView Adapter can distinguish between different ViewHolder types.

    Overwrite the int getItemViewType(int position) method. Add logic to it which determines if the item at position is content or an ad. If you are really sure that after each two content rows, an add will appear, you can just calculate it.

    Use this information in the createViewHolder(ViewGroup parent, int viewType) method to return a different ViewHolder for normal content and adds.