How to place Admob Native Advanced Ads in Firebase recycler view android?

192 Views Asked by At

I have ViewHolder, But I am unable to integrate the native ads in this code, will you please guide me regarding the integration of the native ads in the same code?

How should I integrate the Native ads in this code?

public class ViewHolder extends RecyclerView.ViewHolder  { 
    
    View mView;
    public TextView mLink;
    ImageButton mLikeBtn,mFavBtn,mCopyBtn,mShareBtn,mEditBtn;
    TextView mLikeCount,mAttrText;
    RelativeLayout mRelativeLayout, mControlLayout,mAttribution;
    List<Object> recyclerViewItems;


    public RViewHolder(@NonNull View itemView) {
        super(itemView);

        mView = itemView;
        mLikeBtn =(ImageButton)mView.findViewById(R.id.likeButton);
        mFavBtn =(ImageButton)mView.findViewById(R.id.favButton);
        mLikeCount = (TextView)mView.findViewById(R.id.likeCount);
        mCopyBtn = (ImageButton)mView.findViewById(R.id.copyButton);
        mShareBtn =(ImageButton)mView.findViewById(R.id.shareButton);
        mEditBtn =(ImageButton)mView.findViewById(R.id.logoButton);
        mRelativeLayout =(RelativeLayout)mView.findViewById(R.id.capture);
        mControlLayout =(RelativeLayout)mView.findViewById(R.id.control);
        mAttribution =(RelativeLayout)mView.findViewById(R.id.attribution);

        //item click

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    mClickListener.onItemClick(view, getAdapterPosition() );
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mClickListener.onItemLongClick(view, getAdapterPosition());
                return false;
            }
        });

    }


    public void  setDetails(final android.content.Context ctx, String title, String description, final String image){

        final TextView mTitle = mView.findViewById(R.id.rTitle);
        ImageView mImage = mView.findViewById(R.id.rImageView);
        final TextView mDescription = mView.findViewById(R.id.rDiscription);

        mTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mClickListener != null){
                    int position = getAbsoluteAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        mClickListener.onLinkClick(position);
                    }
                }
            }
        });


        mShareBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Share Button Implementation
                if(mClickListener != null){
                    int position = getAbsoluteAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        mClickListener.onShareClick(position);
                        //Toast.makeText(ctx, "Share: "+mTitle, Toast.LENGTH_SHORT).show();

                    }
                }

            }
        });

        mEditBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mClickListener != null){
                    int position = getAbsoluteAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        mClickListener.onEditClick(position);
                        //Toast.makeText(ctx, "Share: "+mTitle, Toast.LENGTH_SHORT).show();
                    }
                }

            }
        });

        mCopyBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Copy Buttom implementation
                if(mClickListener != null){
                    int position = getAbsoluteAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        try {
                            mClickListener.onCopyClick(position);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });

        mTitle.setText(title);
        mDescription.setText(description);
        Picasso.get().load(image).networkPolicy(NetworkPolicy.OFFLINE).into(mImage, new Callback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError(Exception e) {
                ImageView mImage = mView.findViewById(R.id.rImageView);
                Picasso.get().load(image).into(mImage);

    }


});
        }

    private RViewHolder.ClickListner mClickListener;

    public interface ClickListner{
        void onItemClick(View view, int position) throws IOException;
        void onItemLongClick(View view, int position);
        void onLinkClick(int position);
        void onCopyClick(int position) throws IOException;
        void onShareClick(int position);
        void onEditClick(int position);
    }

    public void setOnClickListener(RViewHolder.ClickListner clickListener){
        mClickListener = clickListener;

    }
    

}

This viewHolder has the like, share and copy button linked to the firebase , please guide me regarding the integration of the native ads

0

There are 0 best solutions below