how to implement slide to next picture in dialog fragment?

merbsmerbs PHMember ✭✭
edited January 2017 in Xamarin.Android

I've been searching for some useful examples on google but I cannot find some.. I'm trying to implement swipe left/right when I click the fragment inside my detail activity, I have 5 ImageView and when you click the image view it will expand in full screen.. , what I want to happen is when you swipe left or right I want to go to the next image.. How can I do this? thank you in advance :)

what I have so far:

MyDialogFragment class.

    public class MyDialogFragment : DialogFragment
         {
        ImageView imgf;

        public static MyDialogFragment newInstance()
        {
            MyDialogFragment f = new MyDialogFragment();
            return f;
        }

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

            SetStyle(DialogFragmentStyle.NoTitle, Android.Resource.Style.ThemeBlackNoTitleBarFullScreen);
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.fragment_dialog, container, false);

            imgf = v.FindViewById<ImageView>(Resource.Id.imageFragment);

            int image = this.Arguments.GetInt("IMG1");

            imgf.SetImageResource(image);

            return v;
        }
    }

My DetailActivity;

 public class DetailActivity : Activity {
 private ImageView mtimg0, mtimg1, mtimg2, mtimg3, mtimg4, mtimg5;        

    protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.detailLayout);

            FindViews();            

            Android.Content.Intent i = this.Intent;
            string iname = i.Extras.GetString("MTNAME");
            int iimg0 = i.Extras.GetInt("IMG0");
            int iimg1 = i.Extras.GetInt("IMG1");
            int iimg2 = i.Extras.GetInt("IMG2");
            int iimg3 = i.Extras.GetInt("IMG3");
            int iimg4 = i.Extras.GetInt("IMG4");
            int iimg5 = i.Extras.GetInt("IMG5");

            tmtname.Text = iname;
            mtimg0.SetImageResource(iimg0);
            mtimg1.SetImageResource(iimg1);
            mtimg2.SetImageResource(iimg2);
            mtimg3.SetImageResource(iimg3);
            mtimg4.SetImageResource(iimg4);
            mtimg5.SetImageResource(iimg5);         

            mtimg0.Click += Mtimg0_Click;
            mtimg1.Click += Mtimg1_Click;
            mtimg2.Click += Mtimg2_Click;
            mtimg3.Click += Mtimg3_Click;
            mtimg4.Click += Mtimg4_Click;
            mtimg5.Click += Mtimg5_Click;
        }

        private void Mtimg0_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg0 = i.Extras.GetInt("IMG0");
            OpenFragment(iimg0);
        }
        private void Mtimg1_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg1 = i.Extras.GetInt("IMG1");
            OpenFragment(iimg1);

        }
        private void Mtimg2_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg2 = i.Extras.GetInt("IMG2");
            OpenFragment(iimg2);        
        }
        private void Mtimg3_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg3 = i.Extras.GetInt("IMG3");
            OpenFragment(iimg3);        
        }
        private void Mtimg4_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg4 = i.Extras.GetInt("IMG4");
            OpenFragment(iimg4);        
        }
        private void Mtimg5_Click(object sender, System.EventArgs e)
        {
            Intent i = this.Intent;
            int iimg5 = i.Extras.GetInt("IMG5");
            OpenFragment(iimg5);
        }

        private void FindViews()
        {
            mtimg0 = FindViewById<ImageView>(Resource.Id.mtimg00); 
            mtimg1 = FindViewById<ImageView>(Resource.Id.mtimg01);
            mtimg2 = FindViewById<ImageView>(Resource.Id.mtimg02);
            mtimg3 = FindViewById<ImageView>(Resource.Id.mtimg03);
            mtimg4 = FindViewById<ImageView>(Resource.Id.mtimg04);
            mtimg5 = FindViewById<ImageView>(Resource.Id.mtimg05);           
            }

            private void OpenFragment(int img1)
            {
                Bundle b = new Bundle();
                b.PutInt("IMG1", img1);

                MyDialogFragment fragment = new MyDialogFragment();
                fragment.Arguments = b;

                fragment.Show(this.FragmentManager, "dialog");
        }
    }
Sign In or Register to comment.