using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Eat.Models; namespace Eat.Controls { class ProductsListViewAdapter : BaseAdapter { public List Products { get; set; } readonly private Context context; public ProductsListViewAdapter(Context context, List items) { this.context = context; Products = items; } public override int Count => Products.Count; public override long GetItemId(int position) { return position; } public override Product this[int position] => Products[position]; public override View GetView(int position, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { row = LayoutInflater.From(context).Inflate(Resource.Layout.products_row, null, false); } void FillTextView(int resourceId, string text, Android.Graphics.Color color) { var textView = row.FindViewById(resourceId); textView.Text = text; textView.SetTextColor(color); } FillTextView(Resource.Id.products_row_name, Products[position].Name, new Android.Graphics.Color(10, 10, 10)); FillTextView(Resource.Id.products_row_kcal, Products[position].Kcal.ToString(), new Android.Graphics.Color(255, 255, 0)); FillTextView(Resource.Id.products_row_fat, Products[position].Fat.ToString(), new Android.Graphics.Color(255, 0, 255)); FillTextView(Resource.Id.products_row_carbs, Products[position].Carbs.ToString(), new Android.Graphics.Color(0, 255, 255)); FillTextView(Resource.Id.products_row_protein, Products[position].Protein.ToString(), new Android.Graphics.Color(100, 100, 20)); FillTextView(Resource.Id.products_row_cost, Products[position].Cost.ToString(), new Android.Graphics.Color(150, 150, 150)); return row; } } }