How to start a new activity from a page adapter and pass list object.Thanks in advance.

JoeyyyyJoeyyyy MYMember ✭✭

This is my page adapter >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;``
using Android.Graphics;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Support.V4.View;
using Java.Lang;
using System.Net;
using Square.Picasso;

    namespace _88MallApp.Droid
    {
        class GalleryAdapter : PagerAdapter
        {
            Context context;
            List<PhotoItem> item;

            public GalleryAdapter(Context context, List<PhotoItem> item)
            {
                this.context = context;
                this.item = item;
            }
            public override int Count
            {
                get { return item.Count; }
            }

            public override Java.Lang.Object InstantiateItem(View container, int position)
            {
                var imageView = new ImageView(context);
                imageView.SetImageBitmap(GetImageBitmapFromUrl(item[position].Path));
                var viewPager = container.JavaCast<ViewPager>();
                viewPager.AddView(imageView);
                imageView.Click += delegate
                {
                    var ViewImage = new Intent(context, typeof(ViewImage));
                    List<IParcelable> parcelList = new List<IParcelable>();
                    foreach (var obj in item)
                    {
                        parcelList.Add(obj);
                    }
                    ViewImage.PutParcelableArrayListExtra("item", parcelList);
                   context.StartActivity(ViewImage);
                    // LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent,
                    //       LinearLayout.LayoutParams.FillParent);

                    //viewPager.LayoutParameters = linearLayoutParams;
                };
                return imageView;
            }

            public override void DestroyItem(View container, int position, Java.Lang.Object view)
            {
                var viewPager = container.JavaCast<ViewPager>();
                viewPager.RemoveView(view as View);
            }

            public override bool IsViewFromObject(View view, Java.Lang.Object obj)
            {
                return view == obj;
            }

            private Bitmap GetImageBitmapFromUrl(string url)
            {
                Bitmap imageBitmap = null;

                using (var webClient = new WebClient())
                {
                    var imageBytes = webClient.DownloadData(url);
                    if (imageBytes != null && imageBytes.Length > 0)
                    {
                        imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                    }
                }

                return imageBitmap;
            }

        }
    }

This is my object;
public class PhotoItem
{
public int Width { get; set; }
public int Height { get; set; }
public string Path { get; set; }
public string ThumbnailPath { get; set; }
}

Sign In or Register to comment.