RecyclerView没有显示 - Xamarin .Droid

时间:2017-07-13 06:34:26

标签: c# android xamarin xamarin.android

对我而言,我的代码似乎没有任何问题,但我的recyclerView没有显示出来。如果适配器设置良好,请查看我的代码。谢谢。请问我的适配器中缺少什么?该页面显示为空,虽然我看到我的适配器中的datasnapShot运行但我的recyclerView没有显示。

适配器

 public class PhotoHolder : RecyclerView.ViewHolder
        {


           public ImageView ImgPhotos;

            public PhotoHolder(View itemView):base(itemView)
            {
                ImgPhotos = (ImageView)itemView.FindViewById(Resource.Id.imageView);

            }

            public class PhotoAdapter : RecyclerView.Adapter, IValueEventListener
            {

                public PhotoAdapter(List<Photos> Photos, Context mContext)
                {
                    this.Photos = Photos;
                    this.mContext = mContext;
                    photos = (PhotosActivity)mContext;

                    mDatabaseImage = FirebaseDatabase.Instance.Reference.Child("Photos");

                    mDatabaseImage.AddValueEventListener(this);
                }



                public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
                {
                    hold = holder as PhotoHolder;
                    hold.ImgPhotos.SetImageResource(Resource.Drawable.cheese_5);
                }



                public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
                {
                    View v = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.list_photos, parent, false);
                    PhotoHolder holder = new PhotoHolder(v);

                    return holder;
                }


                public override int ItemCount
                {

                    get { return Photos.Count; }

                }

                public void OnCancelled(DatabaseError error)
                {
                    throw new NotImplementedException();
                }

               public void OnDataChange(DataSnapshot snapshot)
                {
                    var items = snapshot.Children?.ToEnumerable<DataSnapshot>();


                    foreach (DataSnapshot item in items)
                    {

                        map = (HashMap)item.Value;
                        imageUrl = new FilePhotos(map.Get("URL").ToString());
                    }

                }


            }

        }

光活性

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            FrameLayout content = (FrameLayout)FindViewById(Resource.Id.content_frame);
            LayoutInflater.Inflate(Resource.Layout.PhotoView, content);

            adapter = new PhotoAdapter(Photos, this);

            rv = FindViewById<RecyclerView>(Resource.Id.recyclerView);
            rv.SetLayoutManager(new LinearLayoutManager(this));
            rv.SetItemAnimator(new DefaultItemAnimator());
            rv.SetAdapter(adapter);
            adapter.NotifyDataSetChanged();

        }

0 个答案:

没有答案