Beispiel #1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;
            ReviewAdapterViewHolder holder = null;

            if (view != null)
            {
                holder = view.Tag as ReviewAdapterViewHolder;
            }

            if (holder == null)
            {
                var inflater = context.GetSystemService(Context.LayoutInflaterService).JavaCast <LayoutInflater> ();
                view = inflater.Inflate(Resource.Layout.item_review, parent, false);

                holder = new ReviewAdapterViewHolder {
                    Review = view.FindViewById <TextView> (Resource.Id.item_review),
                    Name   = view.FindViewById <TextView> (Resource.Id.item_author_name),
                    Date   = view.FindViewById <TextView> (Resource.Id.item_date),
                    Rating = view.FindViewById <RatingBar> (Resource.Id.item_rating)
                };

                view.Tag = holder;
            }

            var review = reviews [position];

            holder.Review.Text = string.IsNullOrWhiteSpace(review.Text) ? context.Resources.GetString(Resource.String.rating_only) : review.Text;
            holder.Name.Text   = review.AuthorName;
            holder.Date.Text   = DateTimeUtils.ParseUnixTime(review.Time).ToString("D");
            if (review.Rating < 0)
            {
                holder.Rating.Rating = 0.0F;
            }
            else
            {
                holder.Rating.Rating = (float)Math.Max(review.Rating, 5.0);
            }

            return(view);
        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;
            ReviewAdapterViewHolder holder = null;

            if (view != null)
                holder = view.Tag as ReviewAdapterViewHolder;

            if (holder == null) {
                var inflater = context.GetSystemService (Context.LayoutInflaterService).JavaCast<LayoutInflater> ();
                view = inflater.Inflate (Resource.Layout.item_review, parent, false);

                holder = new ReviewAdapterViewHolder {
                    Review = view.FindViewById<TextView> (Resource.Id.item_review),
                    Name = view.FindViewById<TextView> (Resource.Id.item_author_name),
                    Date = view.FindViewById<TextView> (Resource.Id.item_date),
                    Rating = view.FindViewById<RatingBar> (Resource.Id.item_rating)
                };

                view.Tag = holder;
            }

            var review = reviews [position];
            holder.Review.Text = string.IsNullOrWhiteSpace (review.Text) ? context.Resources.GetString (Resource.String.rating_only) : review.Text;
            holder.Name.Text = review.AuthorName;
            holder.Date.Text = DateTimeUtils.ParseUnixTime (review.Time).ToString ("D");
            if (review.Rating < 0)
                holder.Rating.Rating = 0.0F;
            else
                holder.Rating.Rating = (float)Math.Max (review.Rating, 5.0);

            return view;
        }