Admob in Recyclerview

Hi Guys :smile:

I want to admob in recyclerview
How i can it?

Best Answers

  • ispirLee25ispirLee25 ✭✭
    Accepted Answer

    Thanks, I solved.

    public class RecyclerAdapter : RecyclerView.Adapter
    {
    private List mEmails;
    public RecyclerAdapter(List emails)
    {
    mEmails = emails;
    }

            public override int ItemCount
            {
                get { return mEmails.Count; }
            }
    
            public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
            {
                if (position % 5 == 0)
                {
                    return;
                }
                else
                {
                    MyView myHolder = holder as MyView;
                    myHolder.mName.Text = mEmails[position].Name;
                    myHolder.mSubject.Text = mEmails[position].Subject;
                    myHolder.mMessage.Text = mEmails[position].Message;
                }
            }
    
            public override int GetItemViewType(int position)
            {
                if (position % 5 == 0)
                    return 0;
                return 1;
            }
    
    
    
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
            {
                RecyclerView.ViewHolder viewHolder = null;
                MyView view;
                if (viewType == 1)
                {
                    View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.row, parent, false);
                    TextView txtName = row.FindViewById<TextView>(Resource.Id.txtName);
                    TextView txtSubject = row.FindViewById<TextView>(Resource.Id.txtSubject);
                    TextView txtMessage = row.FindViewById<TextView>(Resource.Id.txtMessage);
                    view = new MyView(row) { mName = txtName, mSubject = txtSubject, mMessage = txtMessage };
                    return view;
                }
                else
                {
                    View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.reklam, parent, false);
                    viewHolder = new ViewHolderAdMob(row);
                    return viewHolder;
                }
    
            }
    
            public class MyView : RecyclerView.ViewHolder
            {
                public View mMainView { get; set; }
                public TextView mName { get; set; }
                public TextView mSubject { get; set; }
                public TextView mMessage { get; set; }
                public MyView(View view) : base(view)
                {
                    mMainView = view;
                    TextView mesaj = view.FindViewById<TextView>(Resource.Id.txtName);
                    CheckBox cbx = view.FindViewById<CheckBox>(Resource.Id.cbxStart);
                    cbx.Visibility = ViewStates.Invisible;
                    mMainView.Click += (sender, e) =>
                    {
                        var context = mMainView.Context;
                        var intent = new Intent(context, typeof(Micerik));
                        intent.PutExtra("sanatci_isim", mesaj.Text);
                        context.StartActivity(intent);
                    };
                }
            }
        }
    

Answers

  • SheemuSheemu USMember ✭✭
  • ispirLee25ispirLee25 Member ✭✭
    Accepted Answer

    Thanks, I solved.

    public class RecyclerAdapter : RecyclerView.Adapter
    {
    private List mEmails;
    public RecyclerAdapter(List emails)
    {
    mEmails = emails;
    }

            public override int ItemCount
            {
                get { return mEmails.Count; }
            }
    
            public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
            {
                if (position % 5 == 0)
                {
                    return;
                }
                else
                {
                    MyView myHolder = holder as MyView;
                    myHolder.mName.Text = mEmails[position].Name;
                    myHolder.mSubject.Text = mEmails[position].Subject;
                    myHolder.mMessage.Text = mEmails[position].Message;
                }
            }
    
            public override int GetItemViewType(int position)
            {
                if (position % 5 == 0)
                    return 0;
                return 1;
            }
    
    
    
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
            {
                RecyclerView.ViewHolder viewHolder = null;
                MyView view;
                if (viewType == 1)
                {
                    View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.row, parent, false);
                    TextView txtName = row.FindViewById<TextView>(Resource.Id.txtName);
                    TextView txtSubject = row.FindViewById<TextView>(Resource.Id.txtSubject);
                    TextView txtMessage = row.FindViewById<TextView>(Resource.Id.txtMessage);
                    view = new MyView(row) { mName = txtName, mSubject = txtSubject, mMessage = txtMessage };
                    return view;
                }
                else
                {
                    View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.reklam, parent, false);
                    viewHolder = new ViewHolderAdMob(row);
                    return viewHolder;
                }
    
            }
    
            public class MyView : RecyclerView.ViewHolder
            {
                public View mMainView { get; set; }
                public TextView mName { get; set; }
                public TextView mSubject { get; set; }
                public TextView mMessage { get; set; }
                public MyView(View view) : base(view)
                {
                    mMainView = view;
                    TextView mesaj = view.FindViewById<TextView>(Resource.Id.txtName);
                    CheckBox cbx = view.FindViewById<CheckBox>(Resource.Id.cbxStart);
                    cbx.Visibility = ViewStates.Invisible;
                    mMainView.Click += (sender, e) =>
                    {
                        var context = mMainView.Context;
                        var intent = new Intent(context, typeof(Micerik));
                        intent.PutExtra("sanatci_isim", mesaj.Text);
                        context.StartActivity(intent);
                    };
                }
            }
        }
    
Sign In or Register to comment.