How to design the given pic using recycler view.

subramanyamnuggusubramanyamnuggu ✭✭✭Member ✭✭✭

How to design the given pic using recycler view. For now i gave only three cards but i will add many as go on and each card will redirect to their respective new page when clicked

APP.png 14.3K

Answers

  • JarvanJarvan Xamurai Member, Xamarin Team Xamurai

    each card will redirect to their respective new page when clicked

    Create a custom adapter and add the click event.

    public class CustomAdapter : RecyclerView.Adapter, View.IOnClickListener
    {
        private Context mContext;
        private List<model> models;
        public CustomAdapter(Context context, List<model> lists)
        {
            this.mContext = context;
            this.models = lists;
        }
        public override int ItemCount
        {
            get { return models.Count; }
        }
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            CustomViewHolder viewHolder = holder as CustomViewHolder;
            viewHolder.text.Text = models[position].content;
            viewHolder.btn1.SetOnClickListener(this);
            viewHolder.btn2.SetOnClickListener(this);
        }
    
        public void OnClick(View v)
        {
            switch (v.Id)
            {
                case Resource.Id.btn1:
                    mContext.StartActivity(new Intent(mContext, typeof(Activity1)));
                    break;
                case Resource.Id.btn2:
                    mContext.StartActivity(new Intent(mContext, typeof(Activity1)));
                    break;
                default:
                    break;
            }
        }
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.item_layout, parent, false);
            CustomViewHolder viewHolder = new CustomViewHolder(itemView);
    
            return viewHolder;
        }
    }
    

    A basic sample, you can refe to the code.

Sign In or Register to comment.