title: Xamarin\Android Development - How do I change Fragments by clicking on a listview item?
body: <p>Here is the bit of code I have so far :</p>
  
  <pre><code>namespace MyTestApp2
  {
      [Activity(Label = "Simple ListView", MainLauncher = true, Icon = "@drawable/icon")]
      public class Activity1 : FragmentActivity {
  
          private CustomViewPager _viewPager;
  
          string[] items;
  
          protected override void OnCreate(Bundle bundle) {
              base.OnCreate(bundle);
  
              SetContentView(Resource.Layout.Main);
              //items = new string[] { "Jon Douglas", "Jax The Cat", "Moxxi The Cat", "Andie The Dog" };
              //ListAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, items);
  
              _viewPager = FindViewById&lt;CustomViewPager&gt;(Resource.Id.ViewPager);
              _viewPager.Adapter = new MyFragmentAdapter(SupportFragmentManager);
  
          }
  
          //protected override void OnListItemClick(ListView l, View v, int position, long id)
          //{
          //    var t = items[position];
          //    Toast.MakeText(this, t, Android.Widget.ToastLength.Short).Show();
          //}
      }
  
      public class MyFragmentAdapter : FragmentPagerAdapter
      {
  
          public MyFragmentAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm)
          {}
  
          public override int Count
          {
              get { 
                   return 5; }
          }
  
          public override Android.Support.V4.App.Fragment GetItem(int position)
          {
              //List&lt;Android.Support.V4.App.Fragment&gt; test = new List&lt;Android.Support.V4.App.Fragment&gt;();
  
              //test.Add(new MyFragment());
              //test.Add(new MyFragment2());
  
              if (position == 0)
                  return new MyFragment();
              else
                  return new MyFragment2();
  
              //return test[position] == null ? new MyFragment() : test[position];
          }
  
          public override void SetPrimaryItem(View container, int position, Java.Lang.Object @object)
          {
              base.SetPrimaryItem(container, position, @object);
          }
      }
  
      public class MyFragment : Android.Support.V4.App.Fragment 
      {
  
          string[] animals = new string[5] { "Tiger", "Lion", "Zebra", "Cheetah", "Giraffe" };
          Context thiscontext;
          public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
          {
  
              var view = inflater.Inflate(Resource.Layout.MyLayout, container, false);
              var test = view.FindViewById&lt;ListView&gt;(Resource.Id.listView1);
  
              thiscontext = container.Context;
  
              test.Adapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleListItem1, animals);
  
  
              test.ItemClick += OnListItemClick;
  
              return view;
             // return base.OnCreateView(inflater, container, savedInstanceState);
          }
  
          void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e)
          {
              //var listView = sender as ListView;
              //var t = animals[e.Position];
              ////Android.Widget.Toast.MakeText(MyFragment.this, "kjh", Android.Widget.ToastLength.Short).Show();
              //Android.Widget.Toast.MakeText(thiscontext, t, ToastLength.Short).Show();
  
              //var adapter = new MyFragmentAdapter(this.FragmentManager);
              //adapter.SetPrimaryItem(this.View, 1, this);
  
              var test = new CustomViewPager(thiscontext, null);
              test.SetCurrentItem(1, true);
  
          }
      }
  
      public class MyFragment2 : Android.Support.V4.App.Fragment
      {
  
          private string[] animals = new string[5] { "Mackeral", "Sea Lion", "Dolphins", "Sardine", "Whales" };
  
          Context thiscontext;
  
          public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
          {
              var view = inflater.Inflate(Resource.Layout.MyLayout, container, false);
              var test = view.FindViewById&lt;ListView&gt;(Resource.Id.listView1);
  
              thiscontext = container.Context;
  
              test.Adapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleListItem1, animals);
  
              test.ItemClick += OnListItemClick;
  
              return view;
              // return base.OnCreateView(inflater, container, savedInstanceState);
          }
  
          void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e)
          {
              var listView = sender as ListView;
              var t = animals[e.Position];
              Android.Widget.Toast.MakeText(thiscontext, t, Android.Widget.ToastLength.Short).Show();
          }
      }
  
      public class CustomViewPager : ViewPager
      {
  
          private bool enabled;
  
          public CustomViewPager(Context context, Android.Util.IAttributeSet attr) : base(context, attr) { this.enabled = true; }
  
          public override bool OnTouchEvent(MotionEvent e)
          {
              if(this.enabled)
                  return base.OnTouchEvent(e);
  
              return false;
          }
  
          public override bool OnInterceptHoverEvent(MotionEvent e)
          {
              if(this.enabled)
                  return base.OnInterceptHoverEvent(e);
  
              return false;
          }
  
          public override void SetCurrentItem(int item, bool smoothScroll)
          {
              base.SetCurrentItem(item, smoothScroll);
          }
      }
  }
  </code></pre>
  
  <p>As you can see from the above, i have attempted to add code to the OnListItemClick event, however, ive not succeeded in changing the fragment.</p>
  
  <p>So, I need the code to do the following :</p>
  
  <ul>
  <li>Not to change pages when swiping left or right</li>
  <li>but only change pages by clicking a list item</li>
  </ul>
  
  <p>Am I going in the right direction ?  </p>