Forum Xamarin.Android

The RecyclerView is showing only one record

Hello everyone my name is Taniguchi and developing a list based on recyclerview, i did a recyclerview but shows only one record
can anyone knows what is happening ?

RecyclerViewAdapter:
public class RecyclerAdapter : RecyclerView.Adapter
{
// add this variable

        private Activity mActivity;
        private MyActionMode mActionMode;
        private List<Email> mEmails;
        private Context context;
        public RecyclerAdapter (List<Email> emails, Context context)
        {
            mEmails = emails;
            this.context = context;
        }
        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;
            }
        }

        public override int ItemCount
        {
            get { return mEmails.Count; }
        }

        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            MyView myHolder = holder as MyView;
            myHolder.mName.Text = mEmails[position].Name;
            myHolder.mSubject.Text = mEmails[position].Subject;
            myHolder.mMessage.Text = mEmails[position].Message;
        }

        public void OnClick(View itemView, int position, bool isLongClick)
        {
            if (isLongClick)
            {
                Toast.MakeText(context, "Long Click : " + mEmails[position], ToastLength.Short).Show();

            }
            else
            {
                Toast.MakeText(context, "Long Click : " + mEmails[position], ToastLength.Short).Show();
            }
        }

        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.row, parent, false);
            TextView txtName = row.FindViewById<TextView>(Resource.Id.textView1);
            TextView txtSubject = row.FindViewById<TextView>(Resource.Id.textView2);
            TextView txtMessage = row.FindViewById<TextView>(Resource.Id.textView3);

            MyView view = new MyView(row) { mName = txtName, mSubject = txtSubject, mMessage = txtMessage };
            return view;
        }
    }

RecyclerViewXML
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.RecyclerView

android:id="@+id/recyclerview"

android:focusable="true"

android:clickable="true"

android:clipToPadding="false"

android:divider="@null"

android:dividerHeight="0dp"

android:layout_width="match_parent"

android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>

Where RecyclerViwer is Called
private RecyclerView mRecyclerView;
private RecyclerView.LayoutManager mLayoutManger;
private RecyclerView.Adapter mAdapter;
private List mEmails;

    protected override void OnCreate(Bundle bundle)
    {   //set our view from the Main  layout Resource
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.activity_main);
        mRecyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerview);
        SetupList();


        //Create our layout Manager
        mLayoutManger = new LinearLayoutManager(this);
        mRecyclerView.SetLayoutManager(mLayoutManger);
        mAdapter = new RecyclerAdapter(mEmails,this);
        mRecyclerView.SetAdapter(mAdapter);

    }

    private void SetupList()
    {
        for (int i = 1; i <= 10; i++)
        {
            mEmails = new List<Email>();
            mEmails.Add(new Email() { Name = "tom", Subject = "Wanna Hang Out?", Message = "I ' ll   be around  tomorrow!!" });
            mEmails.Add(new Email() { Name = "tom", Subject = "Wanna Hang Out?", Message = "I ' ll   be around  tomorrow!!" });
            mEmails.Add(new Email() { Name = "tom", Subject = "Wanna Hang Out?", Message = "I ' ll   be around  tomorrow!!" });
            mEmails.Add(new Email() { Name = "tom", Subject = "Wanna Hang Out?", Message = "I ' ll   be around  tomorrow!!" });
            mEmails.Add(new Email() { Name = "tom", Subject = "Wanna Hang Out?", Message = "I ' ll   be around  tomorrow!!" });
        }
    }

Best Answer

Answers

  • TaniguchiSantosTaniguchiSantos Member ✭✭✭

    Thank you it worked.

Sign In or Register to comment.