public override View GetView(int position, View convertView, ViewGroup parent) { var view = convertView; if (view == null) { view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.userRow, parent, false); var photo = view.FindViewById <ImageView>(Resource.Id.photoImageView); var name = view.FindViewById <TextView>(Resource.Id.nameTextView); var price = view.FindViewById <TextView>(Resource.Id.departmentTextView); var btn = view.FindViewById <Button>(Resource.Id.addProductToCartFromListViewBtn); view.Tag = new ViewHolder() { Photo = photo, Name = name, Price = price, Btn = btn }; } var holder = (ViewHolder)view.Tag; //holder.Photo.SetImageDrawable(ImageManager.Get(parent.Context, users[position].ImageUrl)); //int mydrw = (int)typeof(Resource.Drawable).GetField(products[position].Img).GetValue(null); //holder.Photo.SetImageDrawable(parent.Context.GetDrawable(mydrw)); Picasso.With(parent.Context).Load(products[position].Img).Resize(100, 100).CenterCrop().Into(holder.Photo); holder.Name.Text = products[position].Name; holder.Price.Text = "Cena: " + products[position].Price; var localClickListener = new LocalOnclickListener(); localClickListener.HandleOnClick = () => { SessionService.cart.Products.Add(products[position]); AlertDialog.Builder dialog = new AlertDialog.Builder(parent.Context); AlertDialog alert = dialog.Create(); alert.SetTitle("Dodano produkt"); alert.SetMessage(products[position].Name + " dodany do koszyka."); alert.SetButton("Przejdź do koszyka", (c, ev) => { var intent = new Intent(parent.Context, typeof(CartActivity)); parent.Context.StartActivity(intent); }); alert.SetButton2("Kontynuuj zakupy", (c, ev) => { }); alert.Show(); //var intent = new Intent(parent.Context, typeof(CartActivity)); //parent.Context.StartActivity(intent); //Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(parent.Context); //AlertDialog alert = dialog.Create(); //alert.SetTitle("Add to cart"); //alert.SetMessage(products[position].Name); //alert.SetButton("OK", (c, ev) => { }); //alert.Show(); }; holder.Btn.SetOnClickListener(localClickListener); return(view); }
public override View GetView(int position, View convertView, ViewGroup parent) { var view = convertView; if (view == null) { view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.userRow, parent, false); var photo = view.FindViewById <ImageView>(Resource.Id.photoImageView); var name = view.FindViewById <TextView>(Resource.Id.nameTextView); var price = view.FindViewById <TextView>(Resource.Id.departmentTextView); var btn = view.FindViewById <Button>(Resource.Id.addProductToCartFromListViewBtn); view.Tag = new ViewHolder() { Photo = photo, Name = name, Price = price, Btn = btn }; } var holder = (ViewHolder)view.Tag; //holder.Photo.SetImageDrawable(ImageManager.Get(parent.Context, users[position].ImageUrl)); //int mydrw = (int)typeof(Resource.Drawable).GetField(products[position].Img).GetValue(null); //holder.Photo.SetImageDrawable(parent.Context.GetDrawable(mydrw)); Picasso.With(parent.Context).Load(products[position].Img).Resize(100, 100).CenterCrop().Into(holder.Photo); holder.Name.Text = products[position].Name; holder.Price.Text = "Cena: " + products[position].Price; var localClickListener = new LocalOnclickListener(); localClickListener.HandleOnClick = () => { Toast.MakeText(parent.Context, products[position].Name + " usunięty z koszyka!", ToastLength.Long).Show(); SessionService.cart.Products.Remove(products[position]); this.NotifyDataSetChanged(); decimal sum = 0; foreach (var x in SessionService.cart.Products) { sum += x.Price; } price.Text = sum.ToString(); //nie wiem czemu nie działa }; holder.Btn.SetOnClickListener(localClickListener); //holder.Btn.SetBackgroundDrawable(Resource.Drawable.removeFromCart); holder.Btn.SetBackgroundResource(Resource.Drawable.removeFromCart); return(view); }