Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to Launch a new Fragment from a Fragment with a ListView via an ItemClick event?

Hello everyone,

I've run into a dilemma and I don't seem to be able to find the resources in order to resolve my issue and was hoping I could find some help here.

My app currently has a single Activity which has an ActionBar that inserts/removes fragments into a container. That works peachy. The issue I'm running into is that I have a ListView in two of those Fragments that get inserted via the ActionBar. When one of the items in those ListViews is selected I want to be able to replace the current fragment with a new one to display more information about the item selected. How do I go about doing this? I don't seem to be able to initiate a FragmentTransaction the way I was able to in the original Activity.

Here is the code for Fragment in which contains the ListView that I want to be replaced by another fragment once an item on that ListView is clicked

public class EventListFragment : Fragment
    ListView _eventListView;
    EventAdapter _eventAdapter;

    public override void OnCreate(Bundle savedInstanceState)
        // Create your fragment here

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        System.Diagnostics.Trace.WriteLine("EventListFragment OnCreateView - Got Here!");
        base.OnCreateView(inflater, container, savedInstanceState);
        var view = inflater.Inflate(Resource.Layout.EventList, container, false);
        _eventListView = view.FindViewById<ListView>(Resource.Id.eventListView);
        _eventAdapter = new EventAdapter(this.Activity);
        _eventListView.Adapter = _eventAdapter;
        _eventListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            Event thisEvent = _eventAdapter.GetEventByPosition(e.Position);
            Toast.MakeText(this.Activity, thisEvent.TagLine, ToastLength.Short);
        // Here is where I want to create the new Fragment and dispose of the current one, or place in the background for use of a back button later
        return view;

    public override void OnStart()


Best Answer


  • Ahhh @rzee7, Your hint was indeed most helpful!!! EventHandlers, d'oh! I shall begin work on this shortly :smile:

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Great!! @foosyePhillipWolf

    All the best :smile:

Sign In or Register to comment.